ZQuest Classic Coverage Report


Directory: src/
File: src/zc/maps.cpp
Date: 2025-07-11 05:52:07
Exec Total Coverage
Lines: 4017 5061 79.4%
Functions: 274 320 85.6%
Branches: 3113 5107 61.0%

Line Branch Exec Source
1 #include "base/combo.h"
2 #include "base/handles.h"
3 #include "base/util.h"
4 #include "base/zdefs.h"
5 #include "base/general.h"
6 #include <cstring>
7 #include <assert.h>
8 #include <math.h>
9 #include <vector>
10 #include <deque>
11 #include <string>
12 #include <set>
13 #include <array>
14 #include <sstream>
15 using std::set;
16
17 #include "base/qrs.h"
18 #include "base/dmap.h"
19 #include "base/mapscr.h"
20 #include "base/misctypes.h"
21 #include "base/initdata.h"
22 #include "zc/maps.h"
23 #include "zc/zelda.h"
24 #include "zc/zc_ffc.h"
25 #include "tiles.h"
26 #include "sprite.h"
27 #include "gui/jwin.h"
28 #include "base/zsys.h"
29 #include "subscr.h"
30 #include "zc/zc_subscr.h"
31 #include "zc/hero.h"
32 #include "zc/guys.h"
33 #include "zc/ffscript.h"
34 #include "drawing.h"
35 #include "zc/combos.h"
36 #include "zc/replay.h"
37 #include "slopes.h"
38 #include "particles.h"
39 #include <fmt/format.h>
40 #include "zc/render.h"
41 #include "iter.h"
42 #include <ranges>
43
44 // All the temporary screens (and their layers) for the currently loaded map.
45 static mapscr* temporary_screens[136*7];
46 // Set by load_region.
47 static bool screen_in_current_region[136];
48 407 static rpos_handle_t current_region_rpos_handles[136*7];
49 static bool current_region_rpos_handles_dirty;
50 static int current_region_screen_count;
51 static std::pair<const rpos_handle_t*, int> current_region_rpos_handles_scr[136];
52
53 viewport_t viewport;
54 static int viewport_sprite_uid;
55 ViewportMode viewport_mode;
56 int world_w, world_h;
57 int region_scr_dx, region_scr_dy;
58 int region_scr_count;
59 rpos_t region_max_rpos;
60 int region_num_rpos;
61 region_t cur_region, scrolling_region;
62
63 407 maze_state_t maze_state;
64 int scrolling_maze_last_solved_screen;
65
66 536 void maps_init_game_vars()
67 {
68 536 viewport = {};
69 536 viewport_mode = ViewportMode::CenterAndBound;
70 536 viewport_sprite_uid = 1;
71 536 currscr_for_passive_subscr = -1;
72 536 }
73
74 static region_ids_t current_region_ids;
75
76 14324966 static bool is_a_region(int map, int scr)
77 {
78 14324966 return get_region_id(map, scr) != 0;
79 }
80
81 2232 static bool is_same_region_id(int region_origin_scr, int map, int scr)
82 {
83
2/2
✓ Branch 0 taken 772 times.
✓ Branch 1 taken 1460 times.
2232 if (!is_a_region(map, scr)) return false;
84 1460 int region_id = get_region_id(map, region_origin_scr);
85
1/2
✓ Branch 0 taken 1460 times.
✗ Branch 1 not taken.
1460 return region_id && region_id == get_region_id(map, scr);
86 2232 }
87
88 136579768 bool is_in_current_region(int map, int screen)
89 {
90
5/6
✓ Branch 0 taken 136578195 times.
✓ Branch 1 taken 1573 times.
✓ Branch 2 taken 136578195 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12213 times.
✓ Branch 5 taken 136565982 times.
136579768 return map == cur_map && screen >= 0 && screen < 128 && screen_in_current_region[screen];
91 }
92
93 69621937 bool is_in_current_region(int screen)
94 {
95
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 69621936 times.
69621937 return screen < 128 && screen_in_current_region[screen];
96 }
97
98 28419343 bool is_in_current_region(mapscr* scr)
99 {
100
4/4
✓ Branch 0 taken 28404333 times.
✓ Branch 1 taken 15010 times.
✓ Branch 2 taken 462663 times.
✓ Branch 3 taken 27941670 times.
28419343 return scr->map == cur_map && scr->screen < 128 && screen_in_current_region[scr->screen];
101 }
102
103 bool is_in_scrolling_region(int screen)
104 {
105 if (!screenscrolling) return false;
106
107 int x = screen % 16;
108 int y = screen / 16;
109 return
110 scrolling_region.origin_screen_x >= x && scrolling_region.origin_screen_x < x + scrolling_region.screen_width &&
111 scrolling_region.origin_screen_y >= y && scrolling_region.origin_screen_y < y + scrolling_region.screen_height;
112 }
113
114 8868519286 bool is_in_scrolling_region()
115 {
116 8868519286 return cur_region.screen_count > 1;
117 }
118
119 75343971 bool is_extended_height_mode()
120 {
121
2/2
✓ Branch 0 taken 75093837 times.
✓ Branch 1 taken 250134 times.
75343971 return cur_region.screen_height > 1 && (DMaps[cur_dmap].flags & dmfEXTENDEDVIEWPORT);
122 }
123
124 // Returns 0 if this is not a region.
125 15366152 int get_region_id(int map, int screen)
126 {
127
2/2
✓ Branch 0 taken 401435 times.
✓ Branch 1 taken 14964717 times.
15366152 if (screen >= 128) return 0;
128
2/2
✓ Branch 0 taken 14963617 times.
✓ Branch 1 taken 1100 times.
14964717 if (map == cur_region.map) return current_region_ids[screen];
129
130 1100 return Regions[map].get_region_id(screen);
131 15366152 }
132
133 982758 int get_current_region_id()
134 {
135 982758 return get_region_id(cur_map, cur_screen);
136 }
137
138 63121 void calculate_region(int map, int screen, region_t& region, int& region_scr_dx, int& region_scr_dy)
139 {
140 63121 region.map = map;
141
142
3/4
✓ Branch 0 taken 274 times.
✓ Branch 1 taken 62847 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 274 times.
63121 if (!(is_a_region(map, screen)) || screen >= 0x80)
143 {
144 62847 region.region_id = 0;
145 62847 region.origin_screen = screen;
146 62847 region.origin_screen_x = screen % 16;
147 62847 region.origin_screen_y = screen / 16;
148 62847 region.screen_width = 1;
149 62847 region.screen_height = 1;
150 62847 region.screen_count = 1;
151 62847 region.width = 256;
152 62847 region.height = 176;
153 62847 region_scr_dx = 0;
154 62847 region_scr_dy = 0;
155 62847 return;
156 }
157
158 274 int input_scr_x = screen % 16;
159 274 int input_scr_y = screen / 16;
160
161 // For the given screen, find the top-left corner of its region.
162 274 int origin_scr_x = input_scr_x;
163 274 int origin_scr_y = input_scr_y;
164 274 int origin_scr = screen;
165
2/2
✓ Branch 0 taken 62 times.
✓ Branch 1 taken 372 times.
434 while (origin_scr_x > 0)
166 {
167
2/2
✓ Branch 0 taken 212 times.
✓ Branch 1 taken 160 times.
372 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(origin_scr_x - 1, origin_scr_y))) break;
168 160 origin_scr_x--;
169 }
170
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 414 times.
508 while (origin_scr_y > 0)
171 {
172
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 234 times.
414 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(origin_scr_x, origin_scr_y - 1))) break;
173 234 origin_scr_y--;
174 }
175 274 origin_scr = map_scr_xy_to_index(origin_scr_x, origin_scr_y);
176
177 // Now find the bottom-right corner.
178 274 int region_scr_right = origin_scr_x;
179
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 614 times.
642 while (region_scr_right < 15)
180 {
181
2/2
✓ Branch 0 taken 246 times.
✓ Branch 1 taken 368 times.
614 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(region_scr_right + 1, origin_scr_y))) break;
182 368 region_scr_right++;
183 }
184 274 int region_scr_bottom = origin_scr_y;
185
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 832 times.
856 while (region_scr_bottom < 7)
186 {
187
2/2
✓ Branch 0 taken 250 times.
✓ Branch 1 taken 582 times.
832 if (!is_same_region_id(origin_scr, map, map_scr_xy_to_index(origin_scr_x, region_scr_bottom + 1))) break;
188 582 region_scr_bottom++;
189 }
190
191 274 region.region_id = get_region_id(map, origin_scr);
192 274 region.origin_screen = origin_scr;
193 274 region.origin_screen_x = origin_scr_x;
194 274 region.origin_screen_y = origin_scr_y;
195 274 region.screen_width = region_scr_right - origin_scr_x + 1;
196 274 region.screen_height = region_scr_bottom - origin_scr_y + 1;
197 274 region.screen_count = region.screen_width * region.screen_height;
198 274 region.width = 256 * region.screen_width;
199 274 region.height = 176 * region.screen_height;
200 274 region_scr_dx = input_scr_x - origin_scr_x;
201 274 region_scr_dy = input_scr_y - origin_scr_y;
202
203 DCHECK_RANGE_INCLUSIVE(region.screen_width, 0, 16);
204 DCHECK_RANGE_INCLUSIVE(region.screen_height, 0, 8);
205 63121 }
206
207 35190 void load_region(int dmap, int screen)
208 {
209 35190 clear_temporary_screens();
210
211 35190 int map = DMaps[dmap].map;
212 35190 current_region_ids = Regions[map].get_all_region_ids();
213
214 35190 calculate_region(map, screen, cur_region, region_scr_dx, region_scr_dy);
215 35190 cur_screen = cur_region.origin_screen;
216 35190 world_w = cur_region.width;
217 35190 world_h = cur_region.height;
218 35190 region_scr_count = cur_region.screen_count;
219 35190 region_max_rpos = (rpos_t)(cur_region.screen_count*176 - 1);
220 35190 region_num_rpos = cur_region.screen_count*176;
221 35190 scrolling_maze_last_solved_screen = 0;
222
223 35190 memset(screen_in_current_region, false, sizeof(screen_in_current_region));
224
2/2
✓ Branch 0 taken 35424 times.
✓ Branch 1 taken 35190 times.
70614 for (int x = 0; x < cur_region.screen_width; x++)
225 {
226
2/2
✓ Branch 0 taken 36434 times.
✓ Branch 1 taken 35424 times.
71858 for (int y = 0; y < cur_region.screen_height; y++)
227 {
228 36434 int screen = cur_screen + x + y*16;
229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36434 times.
36434 if (screen < 136)
230 {
231 36434 screen_in_current_region[screen] = true;
232 36434 }
233 36434 }
234 35424 }
235
236 35190 mark_current_region_handles_dirty();
237 35190 }
238
239 35190 static void prepare_current_region_handles()
240 {
241 35190 current_region_rpos_handles_dirty = false;
242 35190 current_region_screen_count = 0;
243
2/2
✓ Branch 0 taken 35538 times.
✓ Branch 1 taken 35190 times.
70728 for (int y = 0; y < cur_region.screen_height; y++)
244 {
245
2/2
✓ Branch 0 taken 36434 times.
✓ Branch 1 taken 35538 times.
71972 for (int x = 0; x < cur_region.screen_width; x++)
246 {
247 36434 int screen = cur_screen + x + y*16;
248 36434 int index_start = current_region_screen_count;
249
2/2
✓ Branch 0 taken 36434 times.
✓ Branch 1 taken 255038 times.
291472 for (int layer = 0; layer <= 6; layer++)
250 {
251 255038 mapscr* scr = get_scr_layer(screen, layer);
252
2/2
✓ Branch 0 taken 83514 times.
✓ Branch 1 taken 171524 times.
255038 if (!scr->is_valid())
253 {
254
1/2
✓ Branch 0 taken 171524 times.
✗ Branch 1 not taken.
171524 if (layer == 0) break;
255 171524 continue;
256 }
257
258 83514 rpos_t base_rpos = POS_TO_RPOS(0, get_region_relative_dx(screen), get_region_relative_dy(screen));
259 83514 current_region_rpos_handles[current_region_screen_count] = {scr, screen, layer, base_rpos, 0};
260 83514 current_region_screen_count += 1;
261 83514 }
262
263 36434 int num_handles_for_scr = current_region_screen_count - index_start;
264 36434 current_region_rpos_handles_scr[screen] = {&current_region_rpos_handles[index_start], num_handles_for_scr};
265 36434 }
266 35538 }
267 35190 }
268
269 1750866400 std::tuple<const rpos_handle_t*, int> get_current_region_handles()
270 {
271 DCHECK(!current_region_rpos_handles_dirty);
272 1750866400 return {current_region_rpos_handles, current_region_screen_count};
273 }
274
275 10841903 std::tuple<const rpos_handle_t*, int> get_current_region_handles(mapscr* scr)
276 {
277 DCHECK(!current_region_rpos_handles_dirty);
278
2/4
✓ Branch 0 taken 10841903 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10841903 times.
10841903 if (scr == special_warp_return_scr || current_region_rpos_handles_dirty)
279 return {nullptr, 0};
280
281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10841903 times.
10841903 if (cur_screen >= 0x80)
282 {
283 DCHECK(scr == origin_scr);
284 return {nullptr, 0};
285 }
286
287 DCHECK(is_in_current_region(scr));
288 10841903 return current_region_rpos_handles_scr[scr->screen];
289 10841903 }
290
291 35190 void mark_current_region_handles_dirty()
292 {
293 35190 current_region_rpos_handles_dirty = true;
294 35190 }
295
296 36288 void clear_temporary_screens()
297 {
298
2/2
✓ Branch 0 taken 34546176 times.
✓ Branch 1 taken 36288 times.
34582464 for (int i = 0; i < 136*7; i++)
299 {
300
2/2
✓ Branch 0 taken 34493172 times.
✓ Branch 1 taken 53004 times.
34546176 if (temporary_screens[i])
301 {
302 53004 free(temporary_screens[i]);
303 53004 temporary_screens[i] = NULL;
304 53004 }
305 34546176 }
306
307 36288 origin_scr = nullptr;
308 36288 hero_scr = nullptr;
309 36288 }
310
311 27526 std::vector<mapscr*> take_temporary_scrs()
312 {
313
1/2
✓ Branch 0 taken 27526 times.
✗ Branch 1 not taken.
27526 std::vector<mapscr*> screens(temporary_screens, temporary_screens + 136*7);
314
2/2
✓ Branch 0 taken 27526 times.
✓ Branch 1 taken 26204752 times.
26232278 for (int i = 0; i < 136*7; i++)
315 26204752 temporary_screens[i] = nullptr;
316
317 27526 return screens;
318
1/2
✓ Branch 0 taken 27526 times.
✗ Branch 1 not taken.
27526 }
319
320 14259973 void calculate_viewport(viewport_t& viewport, int dmap, int screen, int world_w, int world_h, int x, int y)
321 {
322 // TODO: In future, maybe add x/y centering offsets to zscript (Viewport->TargetXOffset/Viewport->TargetYOffset).
323
324
2/2
✓ Branch 0 taken 14213391 times.
✓ Branch 1 taken 46582 times.
14259973 bool extended_height_mode = (DMaps[dmap].flags & dmfEXTENDEDVIEWPORT) && world_h > 176;
325 14259973 viewport.w = 256;
326 14259973 viewport.h = 176 + (extended_height_mode ? 56 : 0);
327
328
2/2
✓ Branch 0 taken 360 times.
✓ Branch 1 taken 14259613 times.
14259973 if (viewport_mode == ViewportMode::Script)
329 360 return;
330
331
2/2
✓ Branch 0 taken 46162 times.
✓ Branch 1 taken 14213451 times.
14259613 if (!is_a_region(DMaps[dmap].map, screen))
332 {
333 14213451 viewport.x = 0;
334 14213451 viewport.y = 0;
335 14213451 }
336
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46162 times.
46162 else if (viewport_mode == ViewportMode::CenterAndBound)
337 {
338 // Clamp the viewport to the edges of the region.
339
6/6
✓ Branch 0 taken 8568 times.
✓ Branch 1 taken 37594 times.
✓ Branch 2 taken 6788 times.
✓ Branch 3 taken 39374 times.
✓ Branch 4 taken 8568 times.
✓ Branch 5 taken 30806 times.
46162 viewport.x = CLAMP(0, world_w - viewport.w, x - viewport.w/2);
340
6/6
✓ Branch 0 taken 11856 times.
✓ Branch 1 taken 34306 times.
✓ Branch 2 taken 5650 times.
✓ Branch 3 taken 40512 times.
✓ Branch 4 taken 11856 times.
✓ Branch 5 taken 28656 times.
46162 viewport.y = CLAMP(0, world_h - viewport.h, y - viewport.h/2);
341 46162 }
342 else if (viewport_mode == ViewportMode::Center)
343 {
344 viewport.x = x - viewport.w/2;
345 viewport.y = y - viewport.h/2;
346 }
347 14259973 }
348
349 14259462 sprite* get_viewport_sprite()
350 {
351 14259462 sprite* spr = sprite::getByUID(viewport_sprite_uid);
352
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 14259456 times.
14259462 if (!spr)
353 {
354 6 viewport_sprite_uid = 1; // Hero uid.
355 6 spr = &Hero;
356 6 }
357
358 14259462 return spr;
359 }
360
361 6 void set_viewport_sprite(sprite* spr)
362 {
363 6 viewport_sprite_uid = spr->uid;
364 6 }
365
366 14231936 void update_viewport()
367 {
368 14231936 sprite* spr = get_viewport_sprite();
369 14231936 int x = spr->x + spr->txsz*16/2;
370 14231936 int y = spr->y + spr->tysz*16/2;
371 14231936 calculate_viewport(viewport, cur_dmap, cur_screen, world_w, world_h, x, y);
372 14231936 }
373
374 14028814 void update_heroscr()
375 {
376 void playLevelMusic();
377
378 14028814 int x = vbound(Hero.getX().getInt(), 0, world_w - 1);
379 14028814 int y = vbound(Hero.getY().getInt(), 0, world_h - 1);
380 14028814 int dx = x / 256;
381 14028814 int dy = y / 176;
382 14028814 int new_screen = cur_screen + dx + dy * 16;
383
2/2
✓ Branch 0 taken 14021052 times.
✓ Branch 1 taken 7762 times.
14028814 if (maze_state.active == 1)
384 7762 new_screen = maze_state.scr->screen;
385
7/12
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 14028598 times.
✓ Branch 2 taken 216 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 216 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 216 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 216 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 216 times.
14028814 if (hero_screen != new_screen && dx >= 0 && dy >= 0 && dx < 16 && dy < 8 && is_in_current_region(new_screen))
386 {
387 216 region_scr_dx = dx;
388 216 region_scr_dy = dy;
389 216 hero_screen = new_screen;
390 216 prev_hero_scr = hero_scr;
391 216 hero_scr = get_scr(hero_screen);
392 216 Hero.screen_spawned = hero_screen;
393 216 playLevelMusic();
394 216 }
395
1/2
✓ Branch 0 taken 14028814 times.
✗ Branch 1 not taken.
14028814 if (game->get_regionmapping() == REGION_MAPPING_PHYSICAL)
396 mark_visited(new_screen); // Mark each screen the hero steps foot in as visited
397 14028814 }
398
399 4722 mapscr* determine_hero_screen_from_coords()
400 {
401 4722 int x = vbound(Hero.getX().getInt(), 0, world_w - 1);
402 4722 int y = vbound(Hero.getY().getInt(), 0, world_h - 1);
403 4722 int dx = x / 256;
404 4722 int dy = y / 176;
405 4722 return get_scr(cur_screen + dx + dy * 16);
406 }
407
408 26503 bool edge_of_region(direction dir)
409 {
410
2/2
✓ Branch 0 taken 26423 times.
✓ Branch 1 taken 80 times.
26503 if (!is_in_scrolling_region()) return true;
411
412 80 int screen_x = hero_screen % 16;
413 80 int screen_y = hero_screen / 16;
414
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 2 times.
80 if (dir == up) screen_y -= 1;
415
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 10 times.
80 if (dir == down) screen_y += 1;
416
2/2
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 30 times.
80 if (dir == left) screen_x -= 1;
417
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 38 times.
80 if (dir == right) screen_x += 1;
418
4/8
✓ Branch 0 taken 80 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 80 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 80 times.
✗ Branch 7 not taken.
80 if (screen_x < 0 || screen_x > 16 || screen_y < 0 || screen_y > 8) return true;
419 80 return !is_in_current_region(map_scr_xy_to_index(screen_x, screen_y));
420 26503 }
421
422 // x, y are world coordinates (aka, in relation to origin screen at the top-left).
423 // Coordinates are clamped to the world bounds.
424 208522629 int get_screen_for_world_xy(int x, int y)
425 {
426
2/2
✓ Branch 0 taken 185735537 times.
✓ Branch 1 taken 22787092 times.
208522629 if (!is_in_scrolling_region())
427 185735537 return cur_screen;
428
429 22787092 int dx = std::clamp(x, 0, world_w - 1) / 256;
430 22787092 int dy = std::clamp(y, 0, world_h - 1) / 176;
431 22787092 int origin_screen_x = cur_screen % 16;
432 22787092 int origin_screen_y = cur_screen / 16;
433 22787092 int scr_x = origin_screen_x + dx;
434 22787092 int scr_y = origin_screen_y + dy;
435 22787092 return map_scr_xy_to_index(scr_x, scr_y);
436 208522629 }
437
438 32518504 int get_screen_for_rpos(rpos_t rpos)
439 {
440 32518504 int origin_screen_x = cur_screen % 16;
441 32518504 int origin_screen_y = cur_screen / 16;
442 32518504 int screen = static_cast<int32_t>(rpos) / 176;
443 32518504 int scr_x = origin_screen_x + screen%cur_region.screen_width;
444 32518504 int scr_y = origin_screen_y + screen/cur_region.screen_width;
445 32518504 return map_scr_xy_to_index(scr_x, scr_y);
446 }
447
448 765972425 rpos_handle_t get_rpos_handle(rpos_t rpos, int layer)
449 {
450 DCHECK_LAYER_ZERO_INDEX(layer);
451
2/2
✓ Branch 0 taken 733591881 times.
✓ Branch 1 taken 32380544 times.
765972425 if (!is_in_scrolling_region())
452 733591881 return {get_scr_layer(cur_screen, layer), cur_screen, layer, rpos, RPOS_TO_POS(rpos)};
453 32380544 int screen = get_screen_for_rpos(rpos);
454 32380544 mapscr* scr = get_scr_layer(screen, layer);
455 32380544 return {scr, screen, layer, rpos, RPOS_TO_POS(rpos)};
456 765972425 }
457
458 // x, y are world coordinates (aka, in relation to origin screen at the top-left).
459 // Coordinates are clamped to the world bounds.
460 3441394080 rpos_handle_t get_rpos_handle_for_world_xy(int x, int y, int layer)
461 {
462 3441394080 x = std::clamp(x, 0, world_w - 1);
463 3441394080 y = std::clamp(y, 0, world_h - 1);
464
465 DCHECK_LAYER_ZERO_INDEX(layer);
466
2/2
✓ Branch 0 taken 3413656908 times.
✓ Branch 1 taken 27737172 times.
3441394080 if (!is_in_scrolling_region())
467 {
468 3413656908 int pos = COMBOPOS(x, y);
469 3413656908 return {get_scr_layer(cur_screen, layer), cur_screen, layer, (rpos_t)pos, pos};
470 }
471 27737172 return get_rpos_handle(COMBOPOS_REGION(x, y), layer);
472 3441394080 }
473
474 // Return a rpos_handle_t for a screen-specific `pos` (0-175).
475 44 rpos_handle_t get_rpos_handle_for_screen(int screen, int layer, int pos)
476 {
477 DCHECK_LAYER_ZERO_INDEX(layer);
478 44 return {get_scr_layer(screen, layer), screen, layer, POS_TO_RPOS(pos, screen), pos};
479 }
480
481 // Return a rpos_handle_t for a screen-specific `pos` (0-175).
482 // Use this instead of the other `get_pos_handle_for_screen` if you already have a reference to the screen.
483 61937 rpos_handle_t get_rpos_handle_for_scr(mapscr* scr, int layer, int pos)
484 {
485 DCHECK_LAYER_ZERO_INDEX(layer);
486 61937 return {scr, scr->screen, layer, POS_TO_RPOS(pos, scr->screen), pos};
487 }
488
489 24643808 void change_rpos_handle_layer(rpos_handle_t& rpos_handle, int layer)
490 {
491 DCHECK_LAYER_ZERO_INDEX(layer);
492 24643808 rpos_handle.layer = layer;
493 24643808 rpos_handle.scr = get_scr_layer(rpos_handle.screen, layer);
494 24643808 }
495
496 // x, y are world coordinates (aka, in relation to origin screen at the top-left).
497 // Coordinates are clamped to the world bounds.
498 52808 combined_handle_t get_combined_handle_for_world_xy(int x, int y, int layer)
499 {
500 DCHECK_LAYER_ZERO_INDEX(layer);
501
502 52808 x = std::clamp(x, 0, world_w - 1);
503 52808 y = std::clamp(y, 0, world_h - 1);
504
505 52808 auto maybe_ffc_handle = getFFCAt(x, y);
506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52808 times.
52808 if (maybe_ffc_handle)
507 return maybe_ffc_handle.value();
508
509 52808 auto rpos = COMBOPOS_REGION_B(x, y);
510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 52808 times.
52808 if (rpos == rpos_t::None)
511 return rpos_handle_t();
512 52808 return get_rpos_handle(rpos, layer);
513 52808 }
514
515 // These functions all return _temporary_ screens. Any modifications made to them (either by the engine
516 // directly or via zscript) only last until the next area is loaded (via loadscr).
517
518 // Returns the screen containing the (x, y) world position.
519 1603401625 mapscr* get_scr_for_world_xy(int x, int y)
520 {
521 // Quick path, but should work the same without.
522
2/2
✓ Branch 0 taken 1592269465 times.
✓ Branch 1 taken 11132160 times.
1603401625 if (!is_in_scrolling_region()) return origin_scr;
523 11132160 return get_scr(get_screen_for_world_xy(x, y));
524 1603401625 }
525
526 24231939 mapscr* get_scr_for_rpos(rpos_t rpos)
527 {
528 // Quick path, but should work the same without.
529
2/2
✓ Branch 0 taken 24093993 times.
✓ Branch 1 taken 137946 times.
24231939 if (!is_in_scrolling_region()) return origin_scr;
530 137946 return get_scr(get_screen_for_rpos(rpos));
531 24231939 }
532
533 14 mapscr* get_scr_for_rpos_layer(rpos_t rpos, int layer)
534 {
535 14 return get_scr_layer(get_screen_for_rpos(rpos), layer);
536 }
537
538 // Note: layer=0 is the base screen, 1 is the first layer, etc.
539 2262979895 mapscr* get_scr_for_world_xy_layer(int x, int y, int layer)
540 {
541 DCHECK_LAYER_ZERO_INDEX(layer);
542
2/2
✓ Branch 0 taken 2251562417 times.
✓ Branch 1 taken 11417478 times.
2262979895 if (!is_in_scrolling_region()) return get_scr_layer(cur_screen, layer);
543
2/2
✓ Branch 0 taken 708094 times.
✓ Branch 1 taken 10709384 times.
11417478 return layer == 0 ?
544 708094 get_scr_for_world_xy(x, y) :
545 10709384 get_scr_layer(get_screen_for_world_xy(x, y), layer);
546 2262979895 }
547
548 1803194207 int get_region_screen_offset(int screen)
549 {
550 1803194207 return get_region_relative_dx(screen) + get_region_relative_dy(screen) * cur_region.screen_width;
551 }
552
553 654673804 int get_screen_for_region_index_offset(int offset)
554 {
555 654673804 int scr_dx = offset % cur_region.screen_width;
556 654673804 int scr_dy = offset / cur_region.screen_width;
557 654673804 int screen = cur_screen + scr_dx + scr_dy*16;
558 654673804 return screen;
559 }
560
561 654489967 mapscr* get_scr_for_region_index_offset(int offset)
562 {
563 654489967 int screen = get_screen_for_region_index_offset(offset);
564 654489967 return get_scr(screen);
565 }
566
567 // The screen at (map, screen) must exist.
568 1412389401 mapscr* get_scr(int map, int screen)
569 {
570 1412389401 mapscr* scr = get_scr_maybe(map, screen);
571
1/2
✓ Branch 0 taken 1412389401 times.
✗ Branch 1 not taken.
1412389401 CHECK(scr);
572 1412389401 return scr;
573 }
574
575 835225958 mapscr* get_scr(int screen)
576 {
577 835225958 return get_scr(cur_map, screen);
578 }
579
580 // Returns null if active screen does not exist.
581 1441932440 mapscr* get_scr_maybe(int map, int screen)
582 {
583 DCHECK_RANGE_INCLUSIVE(screen, 0, 135);
584
585
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1441932440 times.
1441932440 if (map == cur_map)
586 {
587
2/2
✓ Branch 0 taken 1421158348 times.
✓ Branch 1 taken 20774092 times.
1441932440 if (screen == cur_screen)
588 1421158348 return origin_scr;
589
590 20774092 int index = screen*7;
591
2/2
✓ Branch 0 taken 20763002 times.
✓ Branch 1 taken 11090 times.
20774092 if (temporary_screens[index])
592 20763002 return temporary_screens[index];
593
594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11090 times.
11090 if (screen == home_screen)
595 return special_warp_return_scr;
596 11090 }
597
598
3/6
✓ Branch 0 taken 11090 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11090 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11090 times.
11090 if (screenscrolling && map == scrolling_map && !FFCore.ScrollingScreensAll.empty())
599 {
600 11090 int index = screen*7;
601
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11090 times.
11090 if (FFCore.ScrollingScreensAll[index])
602 11090 return FFCore.ScrollingScreensAll[index];
603 }
604
605 return nullptr;
606 1441932440 }
607
608 // Note: layer=0 returns the base screen, layer=1 returns the first layer.
609 6941178920 mapscr* get_scr_layer(int map, int screen, int layer)
610 {
611 DCHECK_LAYER_ZERO_INDEX(layer);
612
2/2
✓ Branch 0 taken 6366391608 times.
✓ Branch 1 taken 574787312 times.
6941178920 if (layer == 0)
613 574787312 return get_scr(map, screen);
614
615
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6366391608 times.
6366391608 if (map == cur_map)
616 {
617 6366391608 int index = screen*7 + layer;
618
2/2
✓ Branch 0 taken 6366323208 times.
✓ Branch 1 taken 68400 times.
6366391608 if (temporary_screens[index])
619 6366323208 return temporary_screens[index];
620
621
2/2
✓ Branch 0 taken 1860 times.
✓ Branch 1 taken 66540 times.
68400 if (screen == home_screen)
622 1860 return &special_warp_return_scrs[layer];
623 66540 }
624
625
1/2
✓ Branch 0 taken 66540 times.
✗ Branch 1 not taken.
66540 if (screenscrolling && map == scrolling_map && !FFCore.ScrollingScreensAll.empty())
626 {
627 66540 int index = screen*7 + layer;
628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66540 times.
66540 if (FFCore.ScrollingScreensAll[index])
629 66540 return FFCore.ScrollingScreensAll[index];
630 }
631
632 NOTREACHED();
633 6941178920 }
634
635 // Note: layer=0 returns the base screen, layer=1 returns the first layer.
636 6548867580 mapscr* get_scr_layer(int screen, int layer)
637 {
638 6548867580 return get_scr_layer(cur_map, screen, layer);
639 }
640
641 // Note: layer=0 returns the base screen, layer=1 returns the first layer.
642 // Return nullptr if screen is not valid.
643 390240105 mapscr* get_scr_layer_valid(int screen, int layer)
644 {
645
2/2
✓ Branch 0 taken 77419620 times.
✓ Branch 1 taken 312820485 times.
390240105 if (mapscr* scr = get_scr_layer(cur_map, screen, layer); scr->is_valid())
646 77419620 return scr;
647 312820485 return nullptr;
648 390240105 }
649
650 389 mapscr* get_scr_current_region_dir(int screen, direction dir)
651 {
652 389 int x = get_region_relative_dx(screen);
653 389 int y = get_region_relative_dy(screen);
654
3/4
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 70 times.
389 if (dir == left && x == 0)
655 70 return nullptr;
656
3/4
✓ Branch 0 taken 89 times.
✓ Branch 1 taken 230 times.
✓ Branch 2 taken 89 times.
✗ Branch 3 not taken.
319 if (dir == right && x == 15)
657 return nullptr;
658
3/4
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 273 times.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
319 if (dir == down && y == 7)
659 return nullptr;
660
3/4
✓ Branch 0 taken 184 times.
✓ Branch 1 taken 135 times.
✓ Branch 2 taken 184 times.
✗ Branch 3 not taken.
319 if (dir == up && y == 0)
661 184 return nullptr;
662
663 135 screen = screen_index_direction(screen, dir);
664
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 135 times.
135 if (is_in_current_region(screen))
665 return get_scr(screen);
666
667 135 return nullptr;
668 389 }
669
670 183837 ffc_handle_t get_ffc_handle(ffc_id_t id)
671 {
672 183837 uint8_t screen = get_screen_for_region_index_offset(id / MAXFFCS);
673 183837 uint8_t i = id % MAXFFCS;
674 183837 mapscr* scr = get_scr(screen);
675 183837 ffcdata* ffc = &scr->getFFC(id % MAXFFCS);
676 183837 return {scr, screen, id, i, ffc};
677 }
678
679 34555 std::pair<int32_t, int32_t> translate_screen_coordinates_to_world(int screen, int x, int y)
680 {
681 34555 x += get_region_relative_dx(screen) * 256;
682 34555 y += get_region_relative_dy(screen) * 176;
683 34555 return {x, y};
684 }
685
686 1044788 std::pair<int32_t, int32_t> translate_screen_coordinates_to_world(int screen)
687 {
688 1044788 int x = get_region_relative_dx(screen) * 256;
689 1044788 int y = get_region_relative_dy(screen) * 176;
690 1044788 return {x, y};
691 }
692
693 11944349093 int32_t COMBOPOS(int32_t x, int32_t y)
694 {
695 DCHECK(x >= 0 && x < 256 && y >= 0 && y < 176);
696 11944349093 return (y & 0xF0) + (x >> 4);
697 }
698 int32_t COMBOPOS_B(int32_t x, int32_t y)
699 {
700 if(unsigned(x) >= 256 || unsigned(y) >= 176)
701 return -1;
702 return (y & 0xF0) + (x >> 4);
703 }
704 3298052321 int32_t COMBOX(int32_t pos)
705 {
706 3298052321 return pos % 16 * 16;
707 }
708 3298052321 int32_t COMBOY(int32_t pos)
709 {
710 3298052321 return pos & 0xF0;
711 }
712
713 111453531 rpos_t COMBOPOS_REGION(int32_t x, int32_t y)
714 {
715
2/2
✓ Branch 0 taken 82900885 times.
✓ Branch 1 taken 28552646 times.
111453531 if (!is_in_scrolling_region())
716 82900885 return (rpos_t) COMBOPOS(x, y);
717
718 DCHECK(is_in_world_bounds(x, y));
719 28552646 int scr_dx = x / (16*16);
720 28552646 int scr_dy = y / (11*16);
721 28552646 int pos = COMBOPOS(x%256, y%176);
722 28552646 return static_cast<rpos_t>((scr_dx + scr_dy * cur_region.screen_width)*176 + pos);
723 111453531 }
724 6207215872 rpos_t COMBOPOS_REGION_B(int32_t x, int32_t y)
725 {
726
2/2
✓ Branch 0 taken 1373828 times.
✓ Branch 1 taken 6205842044 times.
6207215872 if (!is_in_world_bounds(x, y))
727 1373828 return rpos_t::None;
728
729 6205842044 int scr_dx = x / (16*16);
730 6205842044 int scr_dy = y / (11*16);
731 6205842044 int pos = COMBOPOS(x%256, y%176);
732 6205842044 return static_cast<rpos_t>((scr_dx + scr_dy * cur_region.screen_width)*176 + pos);
733 6207215872 }
734 24880979 std::pair<int32_t, int32_t> COMBOXY_REGION(rpos_t rpos)
735 {
736 24880979 int scr_index = static_cast<int32_t>(rpos) / 176;
737 24880979 int scr_dx = scr_index % cur_region.screen_width;
738 24880979 int scr_dy = scr_index / cur_region.screen_width;
739 24880979 int pos = RPOS_TO_POS(rpos);
740 24880979 int x = scr_dx*16*16 + COMBOX(pos);
741 24880979 int y = scr_dy*11*16 + COMBOY(pos);
742 24880979 return {x, y};
743 }
744 60396 int32_t COMBOX_REGION(rpos_t rpos)
745 {
746 60396 auto [x, y] = COMBOXY_REGION(rpos);
747 60396 return x;
748 }
749 12225 int32_t COMBOY_REGION(rpos_t rpos)
750 {
751 12225 auto [x, y] = COMBOXY_REGION(rpos);
752 12225 return y;
753 }
754
755 70177 rpos_t COMBOPOS_REGION_INDEX(int32_t x, int32_t y)
756 {
757 DCHECK(is_in_world_bounds(x, y));
758
1/2
✓ Branch 0 taken 70177 times.
✗ Branch 1 not taken.
70177 if (!is_in_scrolling_region())
759 70177 return (rpos_t)(x + y * 16);
760
761 int scr_dx = x / 16;
762 int scr_dy = y / 11;
763 x %= 16;
764 y %= 11;
765 return static_cast<rpos_t>((scr_dx + scr_dy * cur_region.screen_width)*176 + x + y * 16);
766 70177 }
767 70632 std::pair<int32_t, int32_t> COMBOXY_REGION_INDEX(rpos_t rpos)
768 {
769 70632 int scr_index = static_cast<int32_t>(rpos) / 176;
770 70632 int scr_dx = scr_index % cur_region.screen_width;
771 70632 int scr_dy = scr_index / cur_region.screen_width;
772 70632 int pos = RPOS_TO_POS(rpos);
773 70632 int x = scr_dx*16 + pos%16;
774 70632 int y = scr_dy*11 + pos/16;
775 70632 return {x, y};
776 }
777
778 81093669 int32_t mapind(int32_t map, int32_t scr)
779 {
780 81093669 return map * MAPSCRSNORMAL + scr;
781 }
782
783 FONT *get_zc_font(int index);
784
785 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
786 extern movingblock mblock2; //mblock[4]?
787 extern portal mirror_portal;
788
789 void Z_message_d(const char *format,...)
790 {
791 #ifdef _DEBUG
792 char buf[512];
793 va_list ap;
794 va_start(ap, format);
795 vsprintf(buf, format, ap);
796 va_end(ap);
797
798 al_trace("%s",buf);
799 #else
800 format=format;
801 #endif
802 }
803
804
805
806 bool checktrigger=false;
807
808 void debugging_box(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
809 {
810 //reference/optimization: the start of the unused drawing command index can now be queried. -Gleeok
811 int32_t index = script_drawing_commands.GetNext();
812
813 if(index < 0)
814 return;
815
816 int32_t *sdci = &script_drawing_commands[index][0];
817
818 sdci[0] = RECTR;
819 sdci[1] = 30000;
820 sdci[2] = x1*10000;
821 sdci[3] = y1*10000;
822 sdci[4] = x2*10000;
823 sdci[5] = y2*10000;
824 sdci[6] = 10000;
825 sdci[7] = 10000;
826 sdci[8] = 0;
827 sdci[9] = 0;
828 sdci[10] = 0;
829 sdci[11] = 10000;
830 sdci[12] = 1280000;
831 }
832
833 void clear_dmap(word i)
834 {
835 DMaps[i].clear();
836 }
837
838 void clear_dmaps()
839 {
840 for(int32_t i=0; i<MAXDMAPS; i++)
841 {
842 clear_dmap(i);
843 }
844 }
845
846 219192676 int32_t isdungeon(int32_t dmap, int32_t screen)
847 {
848
2/2
✓ Branch 0 taken 219146996 times.
✓ Branch 1 taken 45680 times.
219192676 if (dmap < 0) dmap = cur_dmap;
849
850 // dungeons can have any dlevel above 0
851
2/2
✓ Branch 0 taken 121451905 times.
✓ Branch 1 taken 97740771 times.
219192676 if((DMaps[dmap].type&dmfTYPE) == dmDNGN)
852 {
853
2/2
✓ Branch 0 taken 9961 times.
✓ Branch 1 taken 97730810 times.
97740771 if (get_canonical_scr(cur_map, screen)->flags6&fCAVEROOM)
854 9961 return 0;
855
856 97730810 return 1;
857 }
858
859 // dlevels that aren't dungeons are caves
860
2/2
✓ Branch 0 taken 36827 times.
✓ Branch 1 taken 121415078 times.
121451905 if (get_canonical_scr(cur_map, screen)->flags6&fDUNGEONROOM)
861 36827 return 1;
862
863 121415078 return 0;
864 219192676 }
865
866 39185844 int32_t isdungeon(int32_t screen)
867 {
868 39185844 return isdungeon(cur_dmap, screen);
869 }
870
871 179881268 int32_t isdungeon()
872 {
873 179881268 return isdungeon(cur_dmap, hero_screen);
874 }
875
876 88223 bool canPermSecret(int32_t dmap, int32_t screen)
877 {
878
2/2
✓ Branch 0 taken 13313 times.
✓ Branch 1 taken 74910 times.
88223 return (!isdungeon(dmap, screen) || get_qr(qr_DUNGEON_DMAPS_PERM_SECRETS));
879 }
880
881 1348852504 int32_t MAPCOMBO(int32_t x, int32_t y)
882 {
883 1348852504 x = vbound(x, 0, world_w-1);
884 1348852504 y = vbound(y, 0, world_h-1);
885 1348852504 int pos = COMBOPOS(x%256, y%176);
886 1348852504 mapscr* scr = get_scr_for_world_xy(x, y);
887 1348852504 return scr->data[pos];
888 }
889
890 //specific layers 1 to 6
891 1673629503 int32_t MAPCOMBOL(int32_t layer,int32_t x,int32_t y)
892 {
893 DCHECK(layer >= 1 && layer <= 6);
894
3/4
✓ Branch 0 taken 1653361041 times.
✓ Branch 1 taken 20268462 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1653361041 times.
1673629503 if (!is_in_world_bounds(x, y) || layer <= 0)
895 20268462 return 0;
896
897 1653361041 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
898
2/2
✓ Branch 0 taken 493348071 times.
✓ Branch 1 taken 1160012970 times.
1653361041 if (!m->is_valid())
899 1160012970 return 0;
900
901 493348071 int pos = COMBOPOS(x%256, y%176);
902 493348071 return m->data[pos];
903 1673629503 }
904
905 int32_t MAPCSETL(int32_t layer,int32_t x,int32_t y)
906 {
907 DCHECK(layer >= 1 && layer <= 6);
908 if (!is_in_world_bounds(x, y) || layer <= 0)
909 return 0;
910
911 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
912 if (!m->is_valid())
913 return 0;
914
915 int pos = COMBOPOS(x%256, y%176);
916 return m->cset[pos];
917 }
918
919 189084 int32_t MAPFLAGL(int32_t layer,int32_t x,int32_t y)
920 {
921 DCHECK(layer >= 1 && layer <= 6);
922
2/4
✓ Branch 0 taken 189084 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 189084 times.
189084 if (!is_in_world_bounds(x, y) || layer <= 0)
923 return 0;
924
925 189084 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
926
2/2
✓ Branch 0 taken 148690 times.
✓ Branch 1 taken 40394 times.
189084 if (!m->is_valid())
927 40394 return 0;
928
929 148690 int pos = COMBOPOS(x%256, y%176);
930 148690 return m->sflag[pos];
931 189084 }
932
933 6281 int32_t COMBOTYPEL(int32_t layer,int32_t x,int32_t y)
934 {
935 DCHECK(layer >= 1 && layer <= 6);
936
2/4
✓ Branch 0 taken 6281 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6281 times.
6281 if (!is_in_world_bounds(x, y) || layer <= 0)
937 return 0;
938
939 6281 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
940
2/2
✓ Branch 0 taken 5809 times.
✓ Branch 1 taken 472 times.
6281 if (!m->is_valid())
941 472 return 0;
942
943 5809 int pos = COMBOPOS(x%256, y%176);
944 5809 return combobuf[m->data[pos]].type;
945 6281 }
946
947 189084 int32_t MAPCOMBOFLAGL(int32_t layer,int32_t x,int32_t y)
948 {
949 DCHECK(layer >= 1 && layer <= 6);
950
2/4
✓ Branch 0 taken 189084 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 189084 times.
189084 if (!is_in_world_bounds(x, y) || layer <= 0)
951 return 0;
952
953 189084 mapscr* m = get_scr_for_world_xy_layer(x, y, layer);
954
2/2
✓ Branch 0 taken 148690 times.
✓ Branch 1 taken 40394 times.
189084 if (!m->is_valid())
955 40394 return 0;
956
957 148690 int pos = COMBOPOS(x%256, y%176);
958 148690 return combobuf[m->data[pos]].flag;
959 189084 }
960
961
962 // True if the FFC covers x, y and is not ethereal or a changer.
963 2458013690 bool ffcIsAt(const ffc_handle_t& ffc_handle, int32_t x, int32_t y)
964 {
965
2/2
✓ Branch 0 taken 737529850 times.
✓ Branch 1 taken 1720483840 times.
2458013690 if (ffc_handle.data()<=0)
966 737529850 return false;
967
968
2/2
✓ Branch 0 taken 300883564 times.
✓ Branch 1 taken 1419600276 times.
1720483840 if((ffc_handle.ffc->flags&(ffc_changer|ffc_ethereal))!=0)
969 300883564 return false;
970
971 1419600276 int32_t fx=ffc_handle.ffc->x.getInt();
972
4/4
✓ Branch 0 taken 976080557 times.
✓ Branch 1 taken 443519719 times.
✓ Branch 2 taken 865979117 times.
✓ Branch 3 taken 110101440 times.
1419600276 if(x<fx || x>fx+(ffc_handle.scr->ffEffectWidth(ffc_handle.i)-1)) // FFC sizes are weird.
973 1309498836 return false;
974
975 110101440 int32_t fy=ffc_handle.ffc->y.getInt();
976
4/4
✓ Branch 0 taken 80120795 times.
✓ Branch 1 taken 29980645 times.
✓ Branch 2 taken 60054856 times.
✓ Branch 3 taken 20065939 times.
110101440 if(y<fy || y>fy+(ffc_handle.scr->ffEffectHeight(ffc_handle.i)-1))
977 90035501 return false;
978
979 20065939 return true;
980 2458013690 }
981
982 978498916 int32_t MAPFFCOMBO(int32_t x,int32_t y)
983 {
984
2/2
✓ Branch 0 taken 13161801 times.
✓ Branch 1 taken 965337115 times.
978498916 if (auto ffc_handle = getFFCAt(x, y))
985 13161801 return ffc_handle->data();
986 965337115 return 0;
987 978498916 }
988
989 206464 int32_t MAPCSET(int32_t x, int32_t y)
990 {
991
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 206464 times.
206464 if (!is_in_world_bounds(x, y))
992 return 0;
993 206464 mapscr* scr = get_scr_for_world_xy(x, y);
994 206464 int pos = COMBOPOS(x%256, y%176);
995 206464 return scr->cset[pos];
996 206464 }
997
998 72555802 int32_t MAPFLAG(int32_t x, int32_t y)
999 {
1000
2/2
✓ Branch 0 taken 27852 times.
✓ Branch 1 taken 72527950 times.
72555802 if (!is_in_world_bounds(x, y))
1001 27852 return 0;
1002 72527950 mapscr* scr = get_scr_for_world_xy(x, y);
1003 72527950 int pos = COMBOPOS(x%256, y%176);
1004 72527950 return scr->sflag[pos];
1005 72555802 }
1006
1007 162875027 int32_t COMBOTYPE(int32_t x,int32_t y)
1008 {
1009 162875027 int32_t b=1;
1010
2/2
✓ Branch 0 taken 95101320 times.
✓ Branch 1 taken 67773707 times.
162875027 if(x&8) b<<=2;
1011
2/2
✓ Branch 0 taken 82071585 times.
✓ Branch 1 taken 80803442 times.
162875027 if(y&8) b<<=1;
1012
1013
2/2
✓ Branch 0 taken 325743016 times.
✓ Branch 1 taken 162867989 times.
488611005 for (int32_t i = 0; i <= 1; ++i)
1014 {
1015
2/2
✓ Branch 0 taken 314598056 times.
✓ Branch 1 taken 11144960 times.
325743016 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1016 {
1017
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 314598056 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
314598056 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && !_walkflag_layer(x, y, i)) return cNONE;
1018 314598056 }
1019 else
1020 {
1021
4/4
✓ Branch 0 taken 10190 times.
✓ Branch 1 taken 11134770 times.
✓ Branch 2 taken 3152 times.
✓ Branch 3 taken 7038 times.
11144960 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && _effectflag_layer(x, y, i)) return cNONE;
1022 }
1023 325735978 }
1024
1025 162867989 newcombo const& cmb = combobuf[MAPCOMBO(x,y)];
1026
5/6
✓ Branch 0 taken 3492064 times.
✓ Branch 1 taken 159375925 times.
✓ Branch 2 taken 2909128 times.
✓ Branch 3 taken 582936 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2909128 times.
162867989 if (cmb.type == cWATER && (cmb.walk&b) && ((cmb.walk>>4)&b))
1027 {
1028
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2909128 times.
2909128 if(cmb.usrflags&cflag4) return cSHALLOWWATER;
1029
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2909128 times.
2909128 if(cmb.usrflags&cflag3) return cNONE;
1030 2909128 }
1031 162867989 return cmb.type;
1032 162875027 }
1033
1034 49376135 int32_t FFCOMBOTYPE(int32_t x,int32_t y)
1035 {
1036 49376135 return combobuf[MAPFFCOMBO(x,y)].type;
1037 }
1038
1039 4910300 int32_t FFORCOMBO(int32_t x, int32_t y)
1040 {
1041
2/2
✓ Branch 0 taken 58516 times.
✓ Branch 1 taken 4851784 times.
4910300 if (auto ffc_handle = getFFCAt(x, y))
1042 58516 return ffc_handle->data();
1043
1044 4851784 return MAPCOMBO(x,y);
1045 4910300 }
1046
1047 int32_t FFORCOMBOTYPE(int32_t x, int32_t y)
1048 {
1049 for (int32_t i = 0; i <= 1; ++i)
1050 {
1051 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1052 {
1053 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,i)) return cNONE;
1054 }
1055 else
1056 {
1057 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && _effectflag_layer(x,y,i)) return cNONE;
1058 }
1059 }
1060 int32_t b=1;
1061
1062 if(x&8) b<<=2;
1063
1064 if(y&8) b<<=1;
1065 newcombo const& cmb = combobuf[FFORCOMBO(x,y)];
1066 if (cmb.type == cWATER && (cmb.usrflags&cflag4) && (cmb.walk&b)) return cSHALLOWWATER;
1067 if (cmb.type == cWATER && (cmb.usrflags&cflag3) && (cmb.walk&b)) return cNONE;
1068 return cmb.type;
1069 }
1070
1071 int32_t FFORCOMBO_L(int32_t layer, int32_t x, int32_t y)
1072 {
1073 if (auto ffc_handle = getFFCAt(x, y))
1074 return ffc_handle->data();
1075
1076 return layer ? MAPCOMBOL(layer, x, y) : MAPCOMBO(x,y);
1077 }
1078
1079 int32_t FFORCOMBOTYPE_L(int32_t layer, int32_t x, int32_t y)
1080 {
1081 return combobuf[FFORCOMBO_L(layer,x,y)].type;
1082 }
1083
1084 69104884 int32_t MAPCOMBOFLAG(int32_t x,int32_t y)
1085 {
1086
2/2
✓ Branch 0 taken 27564 times.
✓ Branch 1 taken 69077320 times.
69104884 if (!is_in_world_bounds(x, y))
1087 27564 return 0;
1088
1089 69077320 mapscr* scr = get_scr_for_world_xy(x, y);
1090 69077320 int pos = COMBOPOS(x%256, y%176);
1091 69077320 return combobuf[scr->data[pos]].flag;
1092 69104884 }
1093
1094 56167043 int32_t MAPFFCOMBOFLAG(int32_t x,int32_t y)
1095 {
1096
2/2
✓ Branch 0 taken 746177 times.
✓ Branch 1 taken 55420866 times.
56167043 if (auto ffc_handle = getFFCAt(x, y))
1097 746177 return ffc_handle->cflag();
1098
1099 55420866 return 0;
1100 56167043 }
1101
1102 1288909483 std::optional<ffc_handle_t> getFFCAt(int32_t x, int32_t y)
1103 {
1104 2764390585 return find_ffc([&](const ffc_handle_t& ffc_handle) {
1105 1475481102 return ffcIsAt(ffc_handle, x, y);
1106 });
1107 }
1108
1109 3043 int32_t MAPCOMBO(const rpos_handle_t& rpos_handle)
1110 {
1111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3043 times.
3043 if (!rpos_handle.scr->is_valid()) return 0;
1112 3043 return rpos_handle.data();
1113 3043 }
1114
1115 3111290244 int32_t MAPCOMBO2(int32_t layer, int32_t x, int32_t y)
1116 {
1117 DCHECK_LAYER_NEG1_INDEX(layer);
1118
2/2
✓ Branch 0 taken 22309461 times.
✓ Branch 1 taken 3088980783 times.
3111290244 if (!is_in_world_bounds(x, y)) return 0;
1119
2/2
✓ Branch 0 taken 3020800841 times.
✓ Branch 1 taken 68179942 times.
3088980783 if (layer == -1) return MAPCOMBO(x, y);
1120
1121 3020800841 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1122
2/2
✓ Branch 0 taken 2069283179 times.
✓ Branch 1 taken 951517662 times.
3020800841 if (!rpos_handle.scr->is_valid()) return 0;
1123
1124 951517662 return rpos_handle.data();
1125 3111290244 }
1126
1127 17186544 static void _handle_screen_load_trigger(const combined_handle_t& handle)
1128 {
1129 17186544 auto cid = handle.data();
1130 17186544 auto* cmb = &handle.combo();
1131 17186544 bool done = false;
1132 17186544 std::set<int32_t> visited;
1133
2/2
✓ Branch 0 taken 17186544 times.
✓ Branch 1 taken 17186544 times.
34373088 while(!done)
1134 {
1135
2/4
✓ Branch 0 taken 17186544 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17186544 times.
17186544 if(visited.contains(cid))
1136 {
1137 Z_error("Combo '%d' was part of an infinite trigger loop, breaking out of loop", cid);
1138 break; // prevent infinite loop
1139 }
1140
1/2
✓ Branch 0 taken 17186544 times.
✗ Branch 1 not taken.
17186544 visited.insert(cid);
1141
1142 17186544 done = true; // don't loop again unless something changes
1143
2/2
✓ Branch 0 taken 17186544 times.
✓ Branch 1 taken 590622 times.
17777166 for(size_t idx = 0; idx < cmb->triggers.size(); ++idx)
1144 {
1145 590622 auto& trig = cmb->triggers[idx];
1146
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 590622 times.
590622 if (trig.triggerflags[4] & combotriggerSCREENLOAD)
1147 do_trigger_combo(handle, idx);
1148 590622 else continue; // can skip checking handle.data()
1149
1150 if(handle.data() != cid)
1151 {
1152 cid = handle.data();
1153 cmb = &handle.combo();
1154 done = false; // loop again for the new combo
1155 break;
1156 }
1157 }
1158 }
1159 17186544 }
1160 51093 static void handle_screen_load_trigger(const screen_handles_t& screen_handles)
1161 {
1162 51093 for_every_combo_in_screen(screen_handles, _handle_screen_load_trigger);
1163 51093 }
1164 34149 void handle_region_load_trigger()
1165 {
1166
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 33997 times.
34149 if (is_in_scrolling_region())
1167 {
1168
2/2
✓ Branch 0 taken 152 times.
✓ Branch 1 taken 19456 times.
19608 for (int screen = 0; screen < 128; screen++)
1169 {
1170
2/2
✓ Branch 0 taken 18156 times.
✓ Branch 1 taken 1300 times.
19456 if (is_in_current_region(screen))
1171 1300 handle_screen_load_trigger(create_screen_handles_one(get_scr(screen)));
1172 19456 }
1173 152 }
1174 33997 else handle_screen_load_trigger(create_screen_handles_one(get_scr(hero_screen)));
1175 34149 }
1176
1177 15796 static void apply_state_changes_to_screen(mapscr& scr, int32_t map, int32_t screen, int32_t flags, bool secrets_do_replay_comment)
1178 {
1179 15796 auto screen_handles = create_screen_handles_one(&scr);
1180
1181
3/4
✓ Branch 0 taken 535 times.
✓ Branch 1 taken 15261 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 535 times.
15796 if ((flags & mSECRET) && canPermSecret(cur_dmap, screen))
1182 {
1183 535 reveal_hidden_stairs(&scr, screen, false);
1184 535 bool do_layers = false;
1185 535 bool from_active_screen = false;
1186 535 trigger_secrets_for_screen_internal(screen_handles, do_layers, from_active_screen, -3, secrets_do_replay_comment);
1187 535 }
1188
1/2
✓ Branch 0 taken 15796 times.
✗ Branch 1 not taken.
15796 if (flags & mLIGHTBEAM)
1189 {
1190 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
1191 if (rpos_handle.ctype() == cLIGHTTARGET)
1192 {
1193 if (!(rpos_handle.combo().usrflags&cflag1)) //Unlit version
1194 rpos_handle.increment_data();
1195 }
1196 });
1197 }
1198
1199 15796 int lvl = DMaps[cur_dmap].level;
1200 15796 toggle_switches(game->lvlswitches[lvl], true, screen_handles);
1201 15796 toggle_gswitches_load(screen_handles);
1202
1203
2/2
✓ Branch 0 taken 15704 times.
✓ Branch 1 taken 92 times.
15796 if(flags&mLOCKBLOCK) // if special stuff done before
1204 {
1205 92 remove_screenstatecombos2(screen_handles, false, cLOCKBLOCK, cLOCKBLOCK2);
1206 92 }
1207
1208
1/2
✓ Branch 0 taken 15796 times.
✗ Branch 1 not taken.
15796 if(flags&mBOSSLOCKBLOCK) // if special stuff done before
1209 {
1210 remove_screenstatecombos2(screen_handles, false, cBOSSLOCKBLOCK, cBOSSLOCKBLOCK2);
1211 }
1212
1213
1/2
✓ Branch 0 taken 15796 times.
✗ Branch 1 not taken.
15796 if(flags&mCHEST) // if special stuff done before
1214 {
1215 remove_screenstatecombos2(screen_handles, false, cCHEST, cCHEST2);
1216 }
1217
1218
1/2
✓ Branch 0 taken 15796 times.
✗ Branch 1 not taken.
15796 if(flags&mCHEST) // if special stuff done before
1219 {
1220 remove_screenstatecombos2(screen_handles, false, cLOCKEDCHEST, cLOCKEDCHEST2);
1221 }
1222
1223
1/2
✓ Branch 0 taken 15796 times.
✗ Branch 1 not taken.
15796 if(flags&mBOSSCHEST) // if special stuff done before
1224 {
1225 remove_screenstatecombos2(screen_handles, false, cBOSSCHEST, cBOSSCHEST2);
1226 }
1227
1228
1229 15796 int mi = mapind(map, screen);
1230 15796 clear_xdoors_mi(screen_handles, mi);
1231 15796 clear_xstatecombos_mi(screen_handles, mi);
1232
1233 15796 handle_screen_load_trigger(screen_handles);
1234 15796 }
1235
1236 53166 std::optional<mapscr> load_temp_mapscr_and_apply_secrets(int32_t map, int32_t screen, int32_t layer, bool secrets, bool secrets_do_replay_comment)
1237 {
1238
2/4
✓ Branch 0 taken 53166 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 53166 times.
53166 if (map < 0 || screen < 0)
1239 return std::nullopt;
1240
1241 53166 const mapscr* source = get_canonical_scr(map, screen);
1242
2/2
✓ Branch 0 taken 40953 times.
✓ Branch 1 taken 12213 times.
53166 if (!source->is_valid())
1243 12213 return std::nullopt;
1244
1245
2/2
✓ Branch 0 taken 8307 times.
✓ Branch 1 taken 32646 times.
40953 if (layer >= 0)
1246 {
1247
2/2
✓ Branch 0 taken 25157 times.
✓ Branch 1 taken 7489 times.
32646 if (source->layermap[layer] <= 0)
1248 25157 return std::nullopt;
1249
1250 7489 source = get_canonical_scr(source->layermap[layer] - 1, source->layerscreen[layer]);
1251
1/2
✓ Branch 0 taken 7489 times.
✗ Branch 1 not taken.
7489 if (!source->is_valid())
1252 return std::nullopt;
1253 7489 }
1254
1255
1/2
✓ Branch 0 taken 15796 times.
✗ Branch 1 not taken.
15796 int flags = secrets ? game->maps[mapind(map, screen)] : 0;
1256 15796 mapscr scr = *source;
1257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15796 times.
15796 apply_state_changes_to_screen(scr, map, screen, flags, secrets_do_replay_comment);
1258
1259 15796 return scr;
1260 53166 }
1261
1262 27203 static int32_t MAPCOMBO3_impl(int32_t map, int32_t screen, int32_t layer, int32_t pos, bool secrets)
1263 {
1264
2/4
✓ Branch 0 taken 27203 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 27203 times.
27203 if (map < 0 || screen < 0) return 0;
1265
1266
2/4
✓ Branch 0 taken 27203 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 27203 times.
27203 if(pos>175 || pos < 0)
1267 return 0;
1268
1269 // TODO: consider caching this (invalidate on any modification via scripting, or anything
1270 // `apply_state_changes_to_screen` checks).
1271
4/5
✓ Branch 0 taken 4976 times.
✓ Branch 1 taken 22227 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4976 times.
✓ Branch 4 taken 22227 times.
32179 if (auto s = load_temp_mapscr_and_apply_secrets(map, screen, layer, secrets))
1272 4976 return s->data[pos];
1273
1274 22227 return 0;
1275 27203 }
1276
1277 // Read from the current temporary screens or, if (map, screen) is not loaded,
1278 // load that screen and apply the relevant secrets before evaluating the combo at that position.
1279 136568978 int32_t MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x, int32_t y, bool secrets)
1280 {
1281 DCHECK_LAYER_NEG1_INDEX(layer);
1282 DCHECK(map >= 0 && screen >= 0);
1283
1284
2/2
✓ Branch 0 taken 136541775 times.
✓ Branch 1 taken 27203 times.
136568978 if (is_in_current_region(map, screen)) return MAPCOMBO2(layer, x, y);
1285
1286 // Screen is not in the current region, so we have to load and trigger some secrets.
1287 27203 int pos = COMBOPOS(x, y);
1288 27203 return MAPCOMBO3_impl(map, screen, layer, pos, secrets);
1289 136568978 }
1290
1291 int32_t MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, rpos_t rpos, bool secrets)
1292 {
1293 DCHECK_LAYER_NEG1_INDEX(layer);
1294 DCHECK(map >= 0 && screen >= 0);
1295 DCHECK(is_valid_rpos(rpos));
1296
1297 if (is_in_current_region(map, screen)) return MAPCOMBO(get_rpos_handle(rpos, layer + 1));
1298
1299 // Screen is not currently loaded, so we have to load and trigger some secrets.
1300 return MAPCOMBO3_impl(map, screen, layer, RPOS_TO_POS(rpos), secrets);
1301 }
1302
1303 int32_t MAPCSET2(int32_t layer,int32_t x,int32_t y)
1304 {
1305 DCHECK_LAYER_NEG1_INDEX(layer);
1306 if (!is_in_world_bounds(x, y))
1307 return 0;
1308 if (layer == -1) return MAPCSET(x, y);
1309
1310 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1311 if (!rpos_handle.scr->is_valid()) return 0;
1312
1313 return rpos_handle.cset();
1314 }
1315
1316 98244774 int32_t MAPFLAG2(int32_t layer,int32_t x,int32_t y)
1317 {
1318 DCHECK_LAYER_NEG1_INDEX(layer);
1319
3/4
✓ Branch 0 taken 1861685 times.
✓ Branch 1 taken 96383089 times.
✓ Branch 2 taken 1861685 times.
✗ Branch 3 not taken.
98244774 if (!get_qr(qr_BUGGED_LAYERED_FLAGS) && (!is_in_world_bounds(x, y)))
1320 return 0;
1321
2/2
✓ Branch 0 taken 80763133 times.
✓ Branch 1 taken 17481641 times.
98244774 if (layer == -1) return MAPFLAG(x, y);
1322
1323 80763133 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1324
2/2
✓ Branch 0 taken 62510399 times.
✓ Branch 1 taken 18252734 times.
80763133 if (!rpos_handle.scr->is_valid()) return 0;
1325
1326 18252734 return rpos_handle.sflag();
1327 98244774 }
1328
1329 2472330 int32_t COMBOTYPE2(int32_t layer,int32_t x,int32_t y)
1330 {
1331
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2472330 times.
2472330 if(layer < 1)
1332 {
1333
2/2
✓ Branch 0 taken 4944660 times.
✓ Branch 1 taken 2472330 times.
7416990 for (int32_t i = layer+1; i <= 1; ++i)
1334 {
1335
2/2
✓ Branch 0 taken 4120908 times.
✓ Branch 1 taken 823752 times.
4944660 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1336 {
1337
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4120908 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4120908 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,i)) return cNONE;
1338 4120908 }
1339 else
1340 {
1341
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 823752 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
823752 if (combobuf[MAPCOMBO2(i,x,y)].type == cBRIDGE && _effectflag_layer(x,y,i)) return cNONE;
1342 }
1343 4944660 }
1344 2472330 }
1345
1/2
✓ Branch 0 taken 2472330 times.
✗ Branch 1 not taken.
2472330 if(layer==-1) return COMBOTYPE(x,y);
1346
1347 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1348 if (!rpos_handle.scr->is_valid()) return 0;
1349
1350 return rpos_handle.ctype();
1351 2472330 }
1352
1353 // Returns the flag for the combo at the given position.
1354 // This is also known as an "inherent flag".
1355 96488269 int32_t MAPCOMBOFLAG2(int32_t layer,int32_t x,int32_t y)
1356 {
1357 DCHECK_LAYER_NEG1_INDEX(layer);
1358
2/2
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 96487981 times.
96488269 if (!is_in_world_bounds(x, y))
1359 288 return 0;
1360
2/2
✓ Branch 0 taken 80704782 times.
✓ Branch 1 taken 15783199 times.
96487981 if (layer == -1) return MAPCOMBOFLAG(x, y);
1361
1362 80704782 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, layer + 1);
1363
2/2
✓ Branch 0 taken 62520063 times.
✓ Branch 1 taken 18184719 times.
80704782 if (!rpos_handle.scr->is_valid()) return 0;
1364
1365 18184719 return rpos_handle.cflag();
1366 96488269 }
1367
1368 11419019 bool HASFLAG(int32_t flag, int32_t layer, rpos_t rpos)
1369 {
1370 DCHECK_LAYER_ZERO_INDEX(layer);
1371 11419019 auto rpos_handle = get_rpos_handle(rpos, layer);
1372
2/2
✓ Branch 0 taken 6346924 times.
✓ Branch 1 taken 5072095 times.
11419019 if (!rpos_handle.scr->is_valid()) return false;
1373
2/2
✓ Branch 0 taken 4565 times.
✓ Branch 1 taken 5067530 times.
5072095 if (rpos_handle.sflag() == flag) return true;
1374
2/2
✓ Branch 0 taken 37705 times.
✓ Branch 1 taken 5029825 times.
5067530 if (rpos_handle.cflag() == flag) return true;
1375 5029825 return false;
1376 11419019 }
1377
1378 1667373 bool HASFLAG_ANY(int32_t flag, rpos_t rpos)
1379 {
1380 DCHECK(is_valid_rpos(rpos));
1381
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1667373 times.
1667373 if (rpos > region_max_rpos) return false;
1382
1383
2/2
✓ Branch 0 taken 11419019 times.
✓ Branch 1 taken 1625103 times.
13044122 for(auto q = 0; q < 7; ++q)
1384 {
1385
2/2
✓ Branch 0 taken 42270 times.
✓ Branch 1 taken 11376749 times.
11419019 if(HASFLAG(flag, q, rpos))
1386 42270 return true;
1387 11376749 }
1388 1625103 return false;
1389 1667373 }
1390
1391 const char *screenstate_string[16] =
1392 {
1393 "Door Up", "Door Down", "Door Left", "Door Right", "Item", "Special Item", "No Return",
1394 "Temporary No Return", "Lock Blocks", "Boss Lock Blocks", "Chests", "Locked Chests",
1395 "Boss Locked Chests", "Secrets", "Visited", "Light Beams"
1396 };
1397
1398 34229 void eventlog_mapflags()
1399 {
1400 34229 std::ostringstream oss;
1401
1402 34229 int mi = mapind(cur_map, home_screen);
1403
1/2
✓ Branch 0 taken 34229 times.
✗ Branch 1 not taken.
34229 word g = game->maps[mi] &0x3FFF;
1404
1405
2/4
✓ Branch 0 taken 34229 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34229 times.
✗ Branch 3 not taken.
34229 oss << fmt::format("Screen ({}, {:02X})", cur_map+1, home_screen);
1406
2/2
✓ Branch 0 taken 6848 times.
✓ Branch 1 taken 27381 times.
34229 if(g) // Main States
1407 {
1408 static const int order[] =
1409 {
1410 mSECRET, mITEM, mSPECIALITEM, mLOCKBLOCK, mBOSSLOCKBLOCK,
1411 mCHEST, mLOCKEDCHEST, mBOSSCHEST,
1412 mDOOR_UP, mDOOR_DOWN, mDOOR_LEFT, mDOOR_RIGHT,
1413 mNEVERRET, mTMPNORET
1414 };
1415
1416
1/2
✓ Branch 0 taken 6848 times.
✗ Branch 1 not taken.
6848 oss << " [";
1417 6848 bool comma = false;
1418
2/2
✓ Branch 0 taken 6848 times.
✓ Branch 1 taken 95872 times.
102720 for(int fl : order)
1419 {
1420
2/2
✓ Branch 0 taken 8647 times.
✓ Branch 1 taken 87225 times.
95872 if(!(g&fl))
1421 87225 continue;
1422 8647 byte ind = byte(log2(double(fl)));
1423
2/2
✓ Branch 0 taken 1799 times.
✓ Branch 1 taken 6848 times.
8647 if(comma)
1424
1/2
✓ Branch 0 taken 1799 times.
✗ Branch 1 not taken.
1799 oss << ", ";
1425
1/2
✓ Branch 0 taken 8647 times.
✗ Branch 1 not taken.
8647 oss << screenstate_string[ind];
1426 8647 comma = true;
1427 }
1428
1/2
✓ Branch 0 taken 6848 times.
✗ Branch 1 not taken.
6848 oss << "]";
1429 6848 }
1430
3/4
✓ Branch 0 taken 34229 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 34197 times.
34229 if(game->xstates[mi]) // ExStates
1431 {
1432
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 oss << " Ex[";
1433 32 bool comma = false;
1434
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 1024 times.
1056 for(byte fl = 0; fl < 32; ++fl)
1435 {
1436
3/4
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✓ Branch 3 taken 992 times.
1024 if(game->xstates[mi] & (1<<fl))
1437 {
1438
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 if(comma)
1439 oss << ", ";
1440
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 oss << int(fl);
1441 32 comma = true;
1442 32 }
1443 1024 }
1444
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 oss << "]";
1445 32 }
1446 { // ExDoors
1447
2/2
✓ Branch 0 taken 34229 times.
✓ Branch 1 taken 136916 times.
171145 for(int q = 0; q < 4; ++q)
1448 {
1449 136916 bool comma = false;
1450
2/4
✓ Branch 0 taken 136916 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 136916 times.
✗ Branch 3 not taken.
136916 if(auto v = game->xdoors[mi][q])
1451 {
1452 if(comma)
1453 oss << ",";
1454 else oss << " ExDoor";
1455 oss << "[" << dirstr[q];
1456 for(int fl = 0; fl < 8; ++fl)
1457 if(v & (1<<fl))
1458 oss << " " << int(fl);
1459 oss << "]";
1460 comma = true;
1461 }
1462 136916 }
1463 }
1464
2/4
✓ Branch 0 taken 34229 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 34229 times.
34229 Z_eventlog("%s\n", oss.str().c_str());
1465 34229 }
1466
1467 // set specific flag
1468 5519 void setmapflag(mapscr* scr, int32_t flag)
1469 {
1470
2/2
✓ Branch 0 taken 5506 times.
✓ Branch 1 taken 13 times.
5519 if (scr->screen >= 0x80) scr = special_warp_return_scr;
1471 5519 int mi = mapind(cur_map, scr->screen);
1472 5519 setmapflag_mi(scr, mi, flag);
1473 5519 }
1474 57 void setmapflag_homescr(int32_t flag)
1475 {
1476 57 int mi = mapind(cur_map, home_screen);
1477 57 setmapflag_mi(origin_scr, mi, flag);
1478 57 }
1479 1986 void setmapflag_mi(int32_t mi, int32_t flag)
1480 {
1481 1986 byte cscr = mi&((1<<7)-1);
1482 1986 byte cmap = (mi>>7);
1483 1986 mapscr* scr = origin_scr;
1484
2/2
✓ Branch 0 taken 809 times.
✓ Branch 1 taken 1177 times.
1986 if (is_in_current_region(cmap, cscr))
1485 1177 scr = get_scr(cmap, cscr);
1486
1487 1986 setmapflag_mi(scr, mi, flag);
1488 1986 }
1489
1490 8333 static void log_state_change(int map, int screen, std::string action)
1491 {
1492
6/6
✓ Branch 0 taken 1886 times.
✓ Branch 1 taken 6447 times.
✓ Branch 2 taken 969 times.
✓ Branch 3 taken 917 times.
✓ Branch 4 taken 352 times.
✓ Branch 5 taken 617 times.
8333 if (is_in_current_region(map, screen) || (map == cur_map && screen == home_screen))
1493 6799 Z_eventlog("[Map %d, Screen %02X (current)] %s\n", map + 1, screen, action.c_str());
1494 else
1495 1534 Z_eventlog("[Map %d, Screen %02X] %s\n", map + 1, screen, action.c_str());
1496 8333 }
1497
1498 7562 void setmapflag_mi(mapscr* scr, int32_t mi, int32_t flag)
1499 {
1500 7562 byte cscr = mi&((1<<7)-1);
1501 7562 byte cmap = (mi>>7);
1502
1503 7562 float temp=log2((float)flag);
1504
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7562 times.
7562 const char* state_string = flag>0 ? screenstate_string[(int32_t)temp] : "<Unknown>";
1505
1506
3/4
✓ Branch 0 taken 7562 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1546 times.
✓ Branch 3 taken 6016 times.
7562 if (replay_is_active() && !(game->maps[mi] & flag))
1507
1/2
✓ Branch 0 taken 6016 times.
✗ Branch 1 not taken.
6016 replay_step_comment(fmt::format("map {} scr {} flag {}", cmap, cscr, state_string));
1508 7562 game->maps[mi] |= flag;
1509
1/2
✓ Branch 0 taken 7562 times.
✗ Branch 1 not taken.
7562 log_state_change(cmap, cscr, fmt::format("State set: {}", state_string));
1510
1511
10/10
✓ Branch 0 taken 5325 times.
✓ Branch 1 taken 2237 times.
✓ Branch 2 taken 3544 times.
✓ Branch 3 taken 1781 times.
✓ Branch 4 taken 2961 times.
✓ Branch 5 taken 583 times.
✓ Branch 6 taken 2808 times.
✓ Branch 7 taken 153 times.
✓ Branch 8 taken 13 times.
✓ Branch 9 taken 2411 times.
9986 if(flag==mSECRET||flag==mITEM||flag==mSPECIALITEM||flag==mLOCKBLOCK||
1512
6/6
✓ Branch 0 taken 2761 times.
✓ Branch 1 taken 47 times.
✓ Branch 2 taken 2616 times.
✓ Branch 3 taken 145 times.
✓ Branch 4 taken 2424 times.
✓ Branch 5 taken 192 times.
2808 flag==mBOSSLOCKBLOCK||flag==mCHEST||flag==mBOSSCHEST||flag==mLOCKEDCHEST)
1513 {
1514 5151 byte nmap=TheMaps[((cmap)*MAPSCRS)+cscr].nextmap;
1515 5151 byte nscr=TheMaps[((cmap)*MAPSCRS)+cscr].nextscr;
1516
1517 5151 std::vector<int32_t> done;
1518
2/2
✓ Branch 0 taken 5036 times.
✓ Branch 1 taken 115 times.
5151 bool looped = (nmap==cmap+1 && nscr==cscr);
1519
1520
6/6
✓ Branch 0 taken 538 times.
✓ Branch 1 taken 5099 times.
✓ Branch 2 taken 52 times.
✓ Branch 3 taken 486 times.
✓ Branch 4 taken 486 times.
✓ Branch 5 taken 5151 times.
5637 while((nmap!=0) && !looped && !(nscr>=128))
1521 {
1522
5/6
✓ Branch 0 taken 364 times.
✓ Branch 1 taken 122 times.
✓ Branch 2 taken 364 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 171 times.
✓ Branch 5 taken 193 times.
486 if((scr->nocarry&flag)!=flag && !(game->maps[((nmap-1)<<7)+nscr] & flag))
1523 {
1524
2/4
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 193 times.
✗ Branch 3 not taken.
193 log_state_change(nmap, nscr, "State change carried over");
1525
2/4
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 193 times.
✗ Branch 3 not taken.
193 if (replay_is_active())
1526
2/4
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 193 times.
✗ Branch 3 not taken.
193 replay_step_comment(fmt::format("map {} scr {} flag {} carry", nmap, nscr, state_string));
1527
1/2
✓ Branch 0 taken 193 times.
✗ Branch 1 not taken.
193 game->maps[((nmap-1)<<7)+nscr] |= flag;
1528 193 }
1529
1530 486 cmap=nmap;
1531 486 cscr=nscr;
1532 486 nmap=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextmap;
1533 486 nscr=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextscr;
1534
1535
2/2
✓ Branch 0 taken 1480 times.
✓ Branch 1 taken 486 times.
1966 for(auto it = done.begin(); it != done.end(); it++)
1536 {
1537
2/2
✓ Branch 0 taken 1428 times.
✓ Branch 1 taken 52 times.
1480 if(*it == ((nmap-1)<<7)+nscr)
1538 52 looped = true;
1539 1480 }
1540
1541
1/2
✓ Branch 0 taken 486 times.
✗ Branch 1 not taken.
486 done.push_back(((nmap-1)<<7)+nscr);
1542 }
1543 5151 }
1544 7562 }
1545
1546 void unsetmapflag_home(int32_t flag, bool anyflag)
1547 {
1548 int mi = mapind(cur_map, home_screen);
1549 unsetmapflag_mi(origin_scr, mi, flag, anyflag);
1550 }
1551
1552 void unsetmapflag(mapscr* scr, int32_t flag, bool anyflag)
1553 {
1554 if (scr->screen >= 0x80) scr = special_warp_return_scr;
1555 int mi = mapind(cur_map, scr->screen);
1556 unsetmapflag_mi(scr, mi, flag, anyflag);
1557 }
1558
1559 471 void unsetmapflag_mi(int32_t mi, int32_t flag, bool anyflag)
1560 {
1561 471 byte cscr = mi&((1<<7)-1);
1562 471 byte cmap = (mi>>7);
1563 471 mapscr* scr = origin_scr;
1564
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 11 times.
471 if (is_in_current_region(cmap, cscr))
1565 11 scr = get_scr(cmap, cscr);
1566
1567 471 unsetmapflag_mi(scr, mi, flag, anyflag);
1568 471 }
1569
1570 471 void unsetmapflag_mi(mapscr* scr, int32_t mi, int32_t flag, bool anyflag)
1571 {
1572 471 byte cscr = mi&((1<<7)-1);
1573 471 byte cmap = (mi>>7);
1574
1575
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 11 times.
471 if(anyflag)
1576 460 game->maps[mi] &= ~flag;
1577
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 else if(flag==mITEM || flag==mSPECIALITEM)
1578 {
1579 if(!(scr->flags4&fNOITEMRESET))
1580 game->maps[mi] &= ~flag;
1581 }
1582 11 else game->maps[mi] &= ~flag;
1583
1584 471 float temp=log2((float)flag);
1585
1/2
✓ Branch 0 taken 471 times.
✗ Branch 1 not taken.
471 const char* state_string = flag>0 ? screenstate_string[(int32_t)temp] : "<Unknown>";
1586
1/2
✓ Branch 0 taken 471 times.
✗ Branch 1 not taken.
471 log_state_change(cmap, cscr, fmt::format("State unset: {}", state_string));
1587
1588
5/10
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 460 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
471 if(flag==mSECRET||flag==mITEM||flag==mSPECIALITEM||flag==mLOCKBLOCK||
1589
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 5 times.
11 flag==mBOSSLOCKBLOCK||flag==mCHEST||flag==mBOSSCHEST||flag==mLOCKEDCHEST)
1590 {
1591 471 byte nmap=TheMaps[((cmap)*MAPSCRS)+cscr].nextmap;
1592 471 byte nscr=TheMaps[((cmap)*MAPSCRS)+cscr].nextscr;
1593
1594 471 std::vector<int32_t> done;
1595
2/2
✓ Branch 0 taken 466 times.
✓ Branch 1 taken 5 times.
471 bool looped = (nmap==cmap+1 && nscr==cscr);
1596
1597
6/6
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 465 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 84 times.
✓ Branch 4 taken 84 times.
✓ Branch 5 taken 471 times.
555 while((nmap!=0) && !looped && !(nscr>=128))
1598 {
1599
4/6
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 72 times.
84 if((scr->nocarry&flag)!=flag && (game->maps[((nmap-1)<<7)+nscr] & flag))
1600 {
1601
2/4
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
72 log_state_change(nmap, nscr, "State change carried over");
1602
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 game->maps[((nmap-1)<<7)+nscr] &= ~flag;
1603 72 }
1604
1605 84 cmap=nmap;
1606 84 cscr=nscr;
1607 84 nmap=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextmap;
1608 84 nscr=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextscr;
1609
1610
2/2
✓ Branch 0 taken 546 times.
✓ Branch 1 taken 84 times.
630 for(std::vector<int32_t>::iterator it = done.begin(); it != done.end(); it++)
1611 {
1612
2/2
✓ Branch 0 taken 540 times.
✓ Branch 1 taken 6 times.
546 if(*it == ((nmap-1)<<7)+nscr)
1613 6 looped = true;
1614 546 }
1615
1616
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 done.push_back(((nmap-1)<<7)+nscr);
1617 }
1618 471 }
1619 471 }
1620
1621 43334551 bool getmapflag(int32_t screen, int32_t flag)
1622 {
1623
2/2
✓ Branch 0 taken 1164399 times.
✓ Branch 1 taken 42170152 times.
43334551 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1624 43334551 return (game->maps[mi] & flag) != 0;
1625 }
1626 160935 bool getmapflag(mapscr* scr, int32_t flag)
1627 {
1628 160935 return getmapflag(scr->screen, flag);
1629 }
1630
1631 54 void setxmapflag(int32_t screen, uint32_t flag)
1632 {
1633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1634 54 setxmapflag_mi(mi, flag);
1635 54 }
1636 56 void setxmapflag_mi(int32_t mi, uint32_t flag)
1637 {
1638
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 35 times.
56 if(game->xstates[mi] & flag) return;
1639 35 byte cscr = mi&((1<<7)-1);
1640 35 byte cmap = (mi>>7);
1641
1642 35 byte temp=(byte)log2((double)flag);
1643
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 log_state_change(cmap, cscr, fmt::format("ExtraState set: {}", temp));
1644
1645 35 game->xstates[mi] |= flag;
1646 56 }
1647 void unsetxmapflag(int32_t screen, uint32_t flag)
1648 {
1649 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1650 unsetxmapflag_mi(mi, flag);
1651 }
1652 void unsetxmapflag_mi(int32_t mi, uint32_t flag)
1653 {
1654 if(!(game->xstates[mi] & flag)) return;
1655 byte cscr = mi&((1<<7)-1);
1656 byte cmap = (mi>>7);
1657 byte temp=(byte)log2((double)flag);
1658 log_state_change(cmap, cscr, fmt::format("ExtraState unset: {}", temp));
1659 game->xstates[mi] &= ~flag;
1660 }
1661 20 bool getxmapflag(int32_t screen, uint32_t flag)
1662 {
1663
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
1664 20 return getxmapflag_mi(mi, flag);
1665 }
1666 462496162 bool getxmapflag_mi(int32_t mi, uint32_t flag)
1667 {
1668 462496162 return (game->xstates[mi] & flag) != 0;
1669 }
1670
1671 void setxdoor_mi(uint mi, uint dir, uint ind, bool state)
1672 {
1673 if(mi > game->xdoors.size() || dir > 3 || ind > 8)
1674 return;
1675 if(!(game->xdoors[mi][dir] & (1<<ind)) == !state)
1676 return;
1677
1678 SETFLAG(game->xdoors[mi][dir], 1<<ind, state);
1679
1680 int cscr = mi % MAPSCRSNORMAL;
1681 int cmap = mi / MAPSCRSNORMAL;
1682 if (state)
1683 log_state_change(cmap, cscr, fmt::format("ExDoor[{}][{}] set", dirstr[dir], ind));
1684 else
1685 log_state_change(cmap, cscr, fmt::format("ExDoor[{}][{}] unset", dirstr[dir], ind));
1686 }
1687 462496128 bool getxdoor_mi(uint mi, uint dir, uint ind)
1688 {
1689
3/6
✓ Branch 0 taken 462496128 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 462496128 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 462496128 times.
462496128 if(mi >= game->xdoors.size() || dir >= 4 || ind >= 8)
1690 return false;
1691 462496128 return (game->xdoors[mi][dir] & (1<<ind));
1692 462496128 }
1693 bool getxdoor(int32_t screen, uint dir, uint ind)
1694 {
1695 int mi = mapind(cur_map, screen);
1696 return getxdoor_mi(mi,dir,ind);
1697 }
1698
1699 389 void set_doorstate_mi(uint mi, uint dir)
1700 {
1701
1/2
✓ Branch 0 taken 389 times.
✗ Branch 1 not taken.
389 if(dir >= 4)
1702 return;
1703 389 setmapflag_mi(mi, mDOOR_UP << dir);
1704
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 388 times.
389 if(auto di = nextscr_mi(mi, dir))
1705 388 setmapflag_mi(*di, mDOOR_UP << oppositeDir[dir]);
1706 389 }
1707 389 void set_doorstate(uint screen, uint dir)
1708 {
1709 389 int mi = mapind(cur_map, screen);
1710 389 set_doorstate_mi(mi, dir);
1711 389 }
1712
1713 void set_xdoorstate_mi(uint mi, uint dir, uint ind, bool state)
1714 {
1715 if(mi >= game->xdoors.size() || dir >= 4 || ind >= 8)
1716 return;
1717 setxdoor_mi(mi, dir, ind, state);
1718 if(auto di = nextscr_mi(mi, dir))
1719 setxdoor_mi(*di, oppositeDir[dir], ind, state);
1720 }
1721
1722 void set_xdoorstate(int32_t screen,uint dir, uint ind, bool state)
1723 {
1724 int mi = mapind(cur_map, screen);
1725 set_xdoorstate_mi(mi, dir, ind, state);
1726 }
1727
1728 57 int32_t WARPCODE(int32_t dmap,int32_t screen,int32_t dw)
1729 // returns: -1 = not a warp screen
1730 // 0+ = warp screen code ( high byte=dmap, low byte=scr )
1731 {
1732 57 const mapscr *scr = get_canonical_scr(DMaps[dmap].map, screen);
1733
1734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if(scr->room!=rWARP)
1735 return -1;
1736
1737 57 int32_t ring=scr->catchall;
1738 57 int32_t size=QMisc.warp[ring].size;
1739
1740
1/2
✓ Branch 0 taken 57 times.
✗ Branch 1 not taken.
57 if(size==0)
1741 return -2;
1742
1743 57 int32_t index=-1;
1744
1745
2/2
✓ Branch 0 taken 289 times.
✓ Branch 1 taken 57 times.
346 for(int32_t i=0; i<size; i++)
1746
6/6
✓ Branch 0 taken 230 times.
✓ Branch 1 taken 59 times.
✓ Branch 2 taken 173 times.
✓ Branch 3 taken 57 times.
✓ Branch 4 taken 173 times.
✓ Branch 5 taken 57 times.
289 if(dmap==QMisc.warp[ring].dmap[i] && screen==
1747 346 (QMisc.warp[ring].scr[i] + DMaps[dmap].xoff))
1748 57 index=i;
1749
1750
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 57 times.
57 if(index==-1)
1751 return -3;
1752
1753 57 index = (index+dw)%size;
1754 57 return (QMisc.warp[ring].dmap[index] << 8) + QMisc.warp[ring].scr[index];
1755 57 }
1756
1757 14498695 void update_combo_cycling()
1758 {
1759 14498695 auto& combo_cache = combo_caches::can_cycle;
1760
1761 static int32_t newdata[176];
1762 static int32_t newcset[176];
1763 static bool initialized=false;
1764
1765 // Just a simple bit of optimization
1766
2/2
✓ Branch 0 taken 14498394 times.
✓ Branch 1 taken 301 times.
14498695 if(!initialized)
1767 {
1768
2/2
✓ Branch 0 taken 52976 times.
✓ Branch 1 taken 301 times.
53277 for(int32_t i=0; i<176; i++)
1769 {
1770 52976 newdata[i]=-1;
1771 52976 newcset[i]=-1;
1772 52976 }
1773
1774 301 initialized=true;
1775 301 }
1776
1777 14498695 std::set<uint16_t> restartanim;
1778
1779
1/2
✓ Branch 0 taken 14498695 times.
✗ Branch 1 not taken.
29386758 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
1780 14888063 int screen = scr->screen;
1781 int32_t x;
1782
1783
2/2
✓ Branch 0 taken 2620299088 times.
✓ Branch 1 taken 14888063 times.
2635187151 for(int32_t i=0; i<176; i++)
1784 {
1785 2620299088 x=scr->data[i];
1786 2620299088 auto& mini_cmb = combo_cache.minis[x];
1787
2/2
✓ Branch 0 taken 3273852 times.
✓ Branch 1 taken 2617025236 times.
2620299088 if (!mini_cmb.can_cycle)
1788 2617025236 continue;
1789
1790 3273852 newcombo const& cmb = combobuf[x];
1791
1792 //time to restart
1793
4/4
✓ Branch 0 taken 902678 times.
✓ Branch 1 taken 2371174 times.
✓ Branch 2 taken 474422 times.
✓ Branch 3 taken 428256 times.
3273852 if ((cmb.aclk>=cmb.speed) && combocheck(cmb))
1794 {
1795 428256 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
1796
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 428256 times.
428256 auto c = cycle_under ? scr->undercombo : cmb.nextcombo;
1797 428256 newdata[i] = c;
1798
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 428240 times.
428256 if(!(cmb.animflags & AF_CYCLENOCSET))
1799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 428240 times.
428240 newcset[i] = cycle_under ? scr->undercset : cmb.nextcset;
1800
1801
2/2
✓ Branch 0 taken 427212 times.
✓ Branch 1 taken 1044 times.
428256 if(combobuf[c].animflags & AF_CYCLE)
1802 {
1803 1044 restartanim.insert(c);
1804 1044 }
1805 428256 }
1806 3273852 }
1807
1808 14888063 int rpos_base = (int)POS_TO_RPOS(0, region_scr_x, region_scr_y);
1809
2/2
✓ Branch 0 taken 2620299088 times.
✓ Branch 1 taken 14888063 times.
2635187151 for(int32_t i=0; i<176; i++)
1810 {
1811
2/2
✓ Branch 0 taken 428256 times.
✓ Branch 1 taken 2619870832 times.
2620299088 if(newdata[i]==-1)
1812 2619870832 continue;
1813
1814 428256 rpos_t rpos = (rpos_t)(rpos_base + i);
1815 428256 rpos_handle_t rpos_handle = {scr, screen, 0, rpos, i};
1816 428256 screen_combo_modify_preroutine(rpos_handle);
1817 428256 scr->data[i]=newdata[i];
1818
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 428240 times.
428256 if(newcset[i]>-1)
1819 428240 scr->cset[i]=newcset[i];
1820 428256 screen_combo_modify_postroutine(rpos_handle);
1821
1822 428256 newdata[i]=-1;
1823 428256 newcset[i]=-1;
1824 428256 }
1825
1826 14888063 word c = scr->numFFC();
1827
2/2
✓ Branch 0 taken 14888063 times.
✓ Branch 1 taken 445020245 times.
459908308 for(word i=0; i<c; i++)
1828 {
1829 445020245 ffcdata& ffc = scr->ffcs[i];
1830 445020245 auto& mini_cmb = combo_cache.minis[ffc.data];
1831
2/2
✓ Branch 0 taken 4173 times.
✓ Branch 1 taken 445016072 times.
445020245 if (!mini_cmb.can_cycle)
1832 445016072 continue;
1833
1834 4173 newcombo const& cmb = combobuf[ffc.data];
1835
1836 //time to restart
1837
4/4
✓ Branch 0 taken 611 times.
✓ Branch 1 taken 3562 times.
✓ Branch 2 taken 503 times.
✓ Branch 3 taken 108 times.
4173 if ((cmb.aclk>=cmb.speed) && combocheck(cmb))
1838 {
1839 108 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
1840
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 auto c = cycle_under ? scr->undercombo : cmb.nextcombo;
1841 108 zc_ffc_set(ffc, c);
1842
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!(cmb.animflags & AF_CYCLENOCSET))
1843
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 ffc.cset = cycle_under ? scr->undercset : cmb.nextcset;
1844
1845
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 60 times.
108 if(combobuf[ffc.data].animflags & AF_CYCLE)
1846 {
1847 60 restartanim.insert(ffc.data);
1848 60 }
1849 108 }
1850 4173 }
1851
1852
2/2
✓ Branch 0 taken 8149027 times.
✓ Branch 1 taken 6739036 times.
14888063 if(get_qr(qr_CMBCYCLELAYERS))
1853 {
1854
2/2
✓ Branch 0 taken 40434216 times.
✓ Branch 1 taken 6739036 times.
47173252 for(int32_t j=1; j<=6; j++)
1855 {
1856 40434216 mapscr* layer_scr = get_scr_layer_valid(screen, j);
1857
2/2
✓ Branch 0 taken 10859573 times.
✓ Branch 1 taken 29574643 times.
40434216 if (!layer_scr)
1858 29574643 continue;
1859
1860
2/2
✓ Branch 0 taken 1911284848 times.
✓ Branch 1 taken 10859573 times.
1922144421 for(int32_t i=0; i<176; i++)
1861 {
1862 1911284848 x=layer_scr->data[i];
1863 1911284848 auto& mini_cmb = combo_cache.minis[x];
1864
2/2
✓ Branch 0 taken 2228558 times.
✓ Branch 1 taken 1909056290 times.
1911284848 if (!mini_cmb.can_cycle)
1865 1909056290 continue;
1866
1867 2228558 newcombo const& cmb = combobuf[x];
1868
1869 //time to restart
1870
4/4
✓ Branch 0 taken 48215 times.
✓ Branch 1 taken 2180343 times.
✓ Branch 2 taken 37350 times.
✓ Branch 3 taken 10865 times.
2228558 if ((cmb.aclk>=cmb.speed) && combocheck(cmb))
1871 {
1872 10865 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
1873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10865 times.
10865 auto c = cycle_under ? layer_scr->undercombo : cmb.nextcombo;
1874 10865 newdata[i] = c;
1875
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10864 times.
10865 if(!(cmb.animflags & AF_CYCLENOCSET))
1876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10864 times.
10864 newcset[i] = cycle_under ? layer_scr->undercset : cmb.nextcset;
1877 1 else newcset[i] = layer_scr->cset[i];
1878
1879
2/2
✓ Branch 0 taken 890 times.
✓ Branch 1 taken 9975 times.
10865 if(combobuf[c].animflags & AF_CYCLE)
1880 {
1881 9975 restartanim.insert(c);
1882 9975 }
1883 10865 }
1884 2228558 }
1885
1886
2/2
✓ Branch 0 taken 1911284848 times.
✓ Branch 1 taken 10859573 times.
1922144421 for (int32_t i=0; i<176; i++)
1887 {
1888
2/2
✓ Branch 0 taken 1911273983 times.
✓ Branch 1 taken 10865 times.
1911284848 if(newdata[i]!=-1)
1889 {
1890 10865 layer_scr->data[i]=newdata[i];
1891
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10865 times.
10865 if(newcset[i]>-1)
1892 10865 layer_scr->cset[i]=newcset[i];
1893 10865 newdata[i]=-1;
1894 10865 newcset[i]=-1;
1895 10865 }
1896 1911284848 }
1897 10859573 }
1898 6739036 }
1899 14888063 });
1900
1901
2/2
✓ Branch 0 taken 14498695 times.
✓ Branch 1 taken 2657 times.
14501352 for (auto i : restartanim)
1902 {
1903 2657 combobuf[i].tile = combobuf[i].o_tile;
1904 2657 combobuf[i].cur_frame=0;
1905 2657 combobuf[i].aclk = 0;
1906
1/2
✓ Branch 0 taken 2657 times.
✗ Branch 1 not taken.
2657 combo_caches::drawing.refresh(i);
1907 }
1908 14498695 }
1909
1910 1194309977 bool iswater_type(int32_t type)
1911 {
1912 // return type==cOLD_WATER || type==cSWIMWARP || type==cDIVEWARP || type==cDIVEWARPB || type==cDIVEWARPC || type==cDIVEWARPD || type==cSWIMWARPB || type==cSWIMWARPC || type==cSWIMWARPD;
1913 1194309977 return (combo_class_buf[type].water!=0);
1914 }
1915
1916 bool iswater(int32_t combo)
1917 {
1918 return iswater_type(combobuf[combo].type) && !DRIEDLAKE;
1919 }
1920 1135408 int32_t iswaterexzq(int32_t combo, int32_t map, int32_t screen, int32_t layer, int32_t x, int32_t y, bool secrets, bool fullcheck, bool LayerCheck)
1921 {
1922 1135408 return iswaterex(combo, map, screen, layer, x, y, secrets, fullcheck, LayerCheck);
1923 }
1924
1925 // (x, y) are world coordinates
1926 57959564 int32_t iswaterex_z3(int32_t combo, int32_t layer, int32_t x, int32_t y, bool secrets, bool fullcheck, bool LayerCheck, bool ShallowCheck, bool hero, optional<combined_handle_t>* out_handle)
1927 {
1928
8/8
✓ Branch 0 taken 57913512 times.
✓ Branch 1 taken 46052 times.
✓ Branch 2 taken 57873237 times.
✓ Branch 3 taken 40275 times.
✓ Branch 4 taken 57806627 times.
✓ Branch 5 taken 66610 times.
✓ Branch 6 taken 59435 times.
✓ Branch 7 taken 57747192 times.
57959564 if (x<0 || x>=world_w || y<0 || y>=world_h)
1929 212372 return false;
1930
1931 57747192 return iswaterex(combo, cur_map, cur_screen, layer, x, y, secrets, fullcheck, LayerCheck, ShallowCheck, hero, out_handle);
1932 57959564 }
1933
1934 96003932 int32_t iswaterex(int32_t combo, int32_t map, int32_t screen, int32_t layer, int32_t x, int32_t y, bool secrets, bool fullcheck, bool LayerCheck, bool ShallowCheck, bool hero, optional<combined_handle_t>* out_handle)
1935 {
1936 DCHECK_LAYER_NEG1_INDEX(layer);
1937 //Honestly, fullcheck is kinda useless... I made this function back when I thought it was checking the entire combo and not just a glorified x/y value.
1938 //Fullcheck makes no sense to ever be on, but hey I guess it's here in case you ever need it...
1939
1940 //Oh hey, Zoras might actually need it. Nevermind, this had a use!
1941
2/2
✓ Branch 0 taken 56819399 times.
✓ Branch 1 taken 39184533 times.
96003932 if (get_qr(qr_SMARTER_WATER))
1942 {
1943
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 56819399 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
56819399 if (DRIEDLAKE) return 0;
1944
5/6
✓ Branch 0 taken 19426056 times.
✓ Branch 1 taken 37393343 times.
✓ Branch 2 taken 6518562 times.
✓ Branch 3 taken 12907494 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6518562 times.
56819399 if (LayerCheck && (get_qr(qr_WATER_ON_LAYER_1) || get_qr(qr_WATER_ON_LAYER_2))) //LayerCheck is a bit dumber, but it lets me add this QR without having to replace all calls, again.
1945 {
1946
2/2
✓ Branch 0 taken 37375822 times.
✓ Branch 1 taken 12234164 times.
49609986 for (int32_t m = layer; m <= 1; m++)
1947 {
1948
5/6
✓ Branch 0 taken 24468328 times.
✓ Branch 1 taken 12907494 times.
✓ Branch 2 taken 12234164 times.
✓ Branch 3 taken 12234164 times.
✓ Branch 4 taken 12234164 times.
✗ Branch 5 not taken.
49609986 if (m < 0 || m == 0 && get_qr(qr_WATER_ON_LAYER_1)
1949
1/2
✓ Branch 0 taken 12234164 times.
✗ Branch 1 not taken.
24468328 || m == 1 && get_qr(qr_WATER_ON_LAYER_2))
1950 {
1951 37375822 int32_t checkwater = iswaterex(combo, map, screen, m, x, y, secrets, fullcheck, false, ShallowCheck);
1952
2/2
✓ Branch 0 taken 36702492 times.
✓ Branch 1 taken 673330 times.
37375822 if (checkwater > 0)
1953 {
1954
2/2
✓ Branch 0 taken 673272 times.
✓ Branch 1 taken 58 times.
673330 if(out_handle) *out_handle = get_rpos_handle_for_world_xy(x, y, m+1);
1955 673330 return checkwater;
1956 }
1957 36702492 }
1958 36702492 }
1959 12234164 return 0;
1960 }
1961 else
1962 {
1963
2/2
✓ Branch 0 taken 43926578 times.
✓ Branch 1 taken 41766713 times.
85693291 for(int32_t i=(fullcheck?3:0); i>=0; i--)
1964 {
1965 43926578 int32_t tx2=((i&2)<<2)+x;
1966 43926578 int32_t ty2=((i&1)<<3)+y;
1967 43926578 int32_t b = i; //Originally b was not needed and I read off i, but then I added the boolean for fullcheck.
1968 //In which case it's just easier to change b if fullcheck is false instead of changing i and potentially screwing up the for loop.
1969
2/2
✓ Branch 0 taken 21673 times.
✓ Branch 1 taken 43904905 times.
43926578 if (!fullcheck)
1970 {
1971 43904905 tx2 = x;
1972 43904905 ty2 = y;
1973
2/2
✓ Branch 0 taken 24650089 times.
✓ Branch 1 taken 19254816 times.
43904905 if(tx2&8) b+=2;
1974
2/2
✓ Branch 0 taken 20345154 times.
✓ Branch 1 taken 23559751 times.
43904905 if(ty2&8) b+=1;
1975 43904905 }
1976
2/2
✓ Branch 0 taken 93980752 times.
✓ Branch 1 taken 43111307 times.
137092059 for (int32_t m = layer; m <= 1; m++)
1977 {
1978 93980752 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2, true)];
1979
2/2
✓ Branch 0 taken 17735727 times.
✓ Branch 1 taken 76245025 times.
93980752 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1980 {
1981
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 17735727 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
17735727 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<b)))
1982 {
1983 return 0;
1984 }
1985 17735727 }
1986 else
1987 {
1988
4/4
✓ Branch 0 taken 159084 times.
✓ Branch 1 taken 76085941 times.
✓ Branch 2 taken 51152 times.
✓ Branch 3 taken 107932 times.
76245025 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<b)))
1989 {
1990 107932 return 0;
1991 }
1992 }
1993
2/2
✓ Branch 0 taken 17735727 times.
✓ Branch 1 taken 76137093 times.
93872820 if (get_qr(qr_NO_SOLID_SWIM))
1994 {
1995
8/14
✓ Branch 0 taken 51152 times.
✓ Branch 1 taken 76085941 times.
✓ Branch 2 taken 51152 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 707339 times.
✓ Branch 5 taken 75378602 times.
✓ Branch 6 taken 3461 times.
✓ Branch 7 taken 703878 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 3461 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
76137093 if ((cmb.type != cBRIDGE || (!get_qr(qr_OLD_BRIDGE_COMBOS) && !(cmb.walk&(0x10<<b)))) && (cmb.walk&(1<<b)) && !((cmb.usrflags&cflag4) && cmb.type == cWATER && (cmb.walk&(0x10<<b)) && ShallowCheck))
1996 {
1997 707339 return 0;
1998 }
1999 75429754 }
2000
3/6
✓ Branch 0 taken 320336 times.
✓ Branch 1 taken 92845145 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 320336 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
93165481 if (iswater_type(cmb.type) && (cmb.walk&(1<<b)) && ((cmb.usrflags&cflag3) || (cmb.usrflags&cflag4)
2001 || (hero && current_item(itype_flippers) < cmb.attribytes[0])
2002 || (hero && ((cmb.usrflags&cflag1) && !(itemsbuf[current_item_id(itype_flippers)].flags & item_flag3)))))
2003 {
2004 if (!(ShallowCheck && (cmb.walk&(1<<b)) && (cmb.usrflags&cflag4))) return 0;
2005 }
2006 93165481 }
2007
2008 130976577 auto found_ffc_not_water = find_ffc([&](const ffc_handle_t& ffc_handle) {
2009
2/2
✓ Branch 0 taken 87337405 times.
✓ Branch 1 taken 527865 times.
87865270 if (ffcIsAt(ffc_handle, tx2, ty2))
2010 {
2011 527865 auto ty = ffc_handle.ctype();
2012
4/6
✓ Branch 0 taken 527865 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 144225 times.
✓ Branch 3 taken 383640 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 144225 times.
527865 if(!combo_class_buf[ty].water && !(ShallowCheck && ty == cSHALLOWWATER))
2013 527865 return true;
2014 }
2015
2016 87337405 return false;
2017 87865270 });
2018
2/2
✓ Branch 0 taken 42583442 times.
✓ Branch 1 taken 527865 times.
43111307 if (found_ffc_not_water) return 0;
2019
2020
2/2
✓ Branch 0 taken 14673 times.
✓ Branch 1 taken 42568769 times.
42583442 if(!i)
2021 {
2022 127582253 auto found_ffc_water = find_ffc([&](const ffc_handle_t& ffc_handle) {
2023
1/2
✓ Branch 0 taken 85013484 times.
✗ Branch 1 not taken.
85013484 if (ffcIsAt(ffc_handle, tx2, ty2))
2024 {
2025 auto ty = ffc_handle.ctype();
2026 if(combo_class_buf[ty].water || (ShallowCheck && ty == cSHALLOWWATER))
2027 return true;
2028 }
2029
2030 85013484 return false;
2031 85013484 });
2032
1/2
✓ Branch 0 taken 42568769 times.
✗ Branch 1 not taken.
42568769 if (found_ffc_water)
2033 {
2034 if(out_handle) *out_handle = *found_ffc_water;
2035 return found_ffc_water->data();
2036 }
2037 42568769 }
2038
2039 42583442 int32_t checkcombo = MAPCOMBO3(map, screen, layer, tx2, ty2, secrets);
2040
2/2
✓ Branch 0 taken 42538948 times.
✓ Branch 1 taken 44494 times.
42583442 if (!(combobuf[checkcombo].walk&(1<<(b+4)))) return 0;
2041
7/12
✓ Branch 0 taken 42258343 times.
✓ Branch 1 taken 280605 times.
✓ Branch 2 taken 10722653 times.
✓ Branch 3 taken 31535690 times.
✓ Branch 4 taken 10244469 times.
✓ Branch 5 taken 478184 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 10244469 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
42538948 if (iswater_type(combobuf[checkcombo].type)||(ShallowCheck && (combobuf[checkcombo].type == cSHALLOWWATER || (iswater_type(combobuf[checkcombo].type) && (combobuf[checkcombo].walk&(1<<b)) && (combobuf[checkcombo].usrflags&cflag4)))))
2042 {
2043
2/2
✓ Branch 0 taken 1227 times.
✓ Branch 1 taken 757562 times.
758789 if (i == 0)
2044 {
2045
2/2
✓ Branch 0 taken 757553 times.
✓ Branch 1 taken 9 times.
757562 if(out_handle) *out_handle = get_rpos_handle_for_world_xy(tx2, ty2, layer+1);
2046 757562 return checkcombo;
2047 }
2048 1227 }
2049 41781386 }
2050 41766713 return 0;
2051 }
2052 }
2053 else
2054 {
2055 39184533 int32_t b = 0;
2056
2/2
✓ Branch 0 taken 20328162 times.
✓ Branch 1 taken 18856371 times.
39184533 if(x&8) b+=2;
2057
2/2
✓ Branch 0 taken 15176866 times.
✓ Branch 1 taken 24007667 times.
39184533 if(y&8) b+=1;
2058
1/2
✓ Branch 0 taken 39184533 times.
✗ Branch 1 not taken.
39184533 if (get_qr(qr_NO_SOLID_SWIM))
2059 {
2060 if (combobuf[combo].walk&(1<<b))
2061 {
2062 return 0;
2063 }
2064 }
2065
1/2
✓ Branch 0 taken 39184533 times.
✗ Branch 1 not taken.
39184533 if (!(combobuf[combo].walk&(1<<(b+4)))) return 0;
2066
8/8
✓ Branch 0 taken 37613714 times.
✓ Branch 1 taken 1570819 times.
✓ Branch 2 taken 167945 times.
✓ Branch 3 taken 37445769 times.
✓ Branch 4 taken 2129 times.
✓ Branch 5 taken 1668985 times.
✓ Branch 6 taken 163774 times.
✓ Branch 7 taken 161691 times.
39184533 if((iswater_type(combobuf[combo].type) || (ShallowCheck && combobuf[combo].type == cSHALLOWWATER)) && !DRIEDLAKE)
2067 {
2068
2/2
✓ Branch 0 taken 1830646 times.
✓ Branch 1 taken 30 times.
1830676 if(out_handle) *out_handle = get_rpos_handle_for_world_xy(x, y, 0); //NOTE: This is only correct assuming 'combo' is 'MAPCOMBO(x,y)'
2069 1830676 return combo;
2070 }
2071 37609543 return 0;
2072 }
2073 96259618 }
2074
2075 326 bool isdamage_type(int32_t type)
2076 {
2077
1/2
✓ Branch 0 taken 326 times.
✗ Branch 1 not taken.
326 switch(type)
2078 {
2079 case cDAMAGE1: case cDAMAGE2: case cDAMAGE3: case cDAMAGE4:
2080 case cDAMAGE5: case cDAMAGE6: case cDAMAGE7:
2081 return true;
2082 }
2083 326 return false;
2084 326 }
2085
2086 2515318939 bool ispitfall_type(int32_t type)
2087 {
2088 2515318939 return combo_class_buf[type].pit != 0;
2089 }
2090
2091 2515318939 bool ispitfall(int32_t combo)
2092 {
2093 2515318939 return ispitfall_type(combobuf[combo].type);
2094 }
2095
2096 270179271 bool ispitfall(int32_t x, int32_t y)
2097 {
2098
2/2
✓ Branch 0 taken 1454897 times.
✓ Branch 1 taken 268724374 times.
270179271 if(int32_t c = MAPFFCOMBO(x,y))
2099 {
2100 1454897 return ispitfall(c) ? true : false;
2101 }
2102 268724374 int32_t c = MAPCOMBOL(2,x,y);
2103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 268724374 times.
268724374 if(ispitfall(c)) return true;
2104
2/2
✓ Branch 0 taken 255646867 times.
✓ Branch 1 taken 13077507 times.
268724374 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2105 {
2106
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 255646867 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
255646867 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1)) return false;
2107 255646867 }
2108 else
2109 {
2110
3/4
✓ Branch 0 taken 340 times.
✓ Branch 1 taken 13077167 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 340 times.
13077507 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1)) return false;
2111 }
2112 268724034 c = MAPCOMBOL(1,x,y);
2113
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 268724010 times.
268724034 if(ispitfall(c)) return true;
2114
2115
2/2
✓ Branch 0 taken 255646867 times.
✓ Branch 1 taken 13077143 times.
268724010 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2116 {
2117
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 255646867 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
255646867 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,0)) return false;
2118 255646867 }
2119 else
2120 {
2121
4/4
✓ Branch 0 taken 13072 times.
✓ Branch 1 taken 13064071 times.
✓ Branch 2 taken 8777 times.
✓ Branch 3 taken 4295 times.
13077143 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,0)) return false;
2122 }
2123 268715233 c = MAPCOMBO(x,y);
2124
2/2
✓ Branch 0 taken 70742 times.
✓ Branch 1 taken 268644491 times.
268715233 if(ispitfall(c)) return true;
2125 268644491 return false;
2126 270179271 }
2127
2128 575457040 int32_t getpitfall(int32_t x, int32_t y) //Return the highest-layer active pit combo at the given position
2129 {
2130
2/2
✓ Branch 0 taken 9280299 times.
✓ Branch 1 taken 566176741 times.
575457040 if(int32_t c = MAPFFCOMBO(x,y))
2131 {
2132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9280299 times.
9280299 return ispitfall(c) ? c : 0;
2133 }
2134 566176741 int32_t c = MAPCOMBOL(2,x,y);
2135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 566176741 times.
566176741 if(ispitfall(c)) return c;
2136
2137
2/2
✓ Branch 0 taken 523020543 times.
✓ Branch 1 taken 43156198 times.
566176741 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2138 {
2139
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 523020543 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
523020543 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1)) return 0;
2140 523020543 }
2141 else
2142 {
2143
3/4
✓ Branch 0 taken 3132 times.
✓ Branch 1 taken 43153066 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3132 times.
43156198 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1)) return 0;
2144 }
2145 566173609 c = MAPCOMBOL(1,x,y);
2146
2/2
✓ Branch 0 taken 278 times.
✓ Branch 1 taken 566173331 times.
566173609 if(ispitfall(c)) return c;
2147
2148
2/2
✓ Branch 0 taken 523020543 times.
✓ Branch 1 taken 43152788 times.
566173331 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2149 {
2150
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 523020543 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
523020543 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,0)) return 0;
2151 523020543 }
2152 else
2153 {
2154
4/4
✓ Branch 0 taken 144357 times.
✓ Branch 1 taken 43008431 times.
✓ Branch 2 taken 103729 times.
✓ Branch 3 taken 40628 times.
43152788 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,0)) return 0;
2155 }
2156 566069602 c = MAPCOMBO(x,y);
2157
2/2
✓ Branch 0 taken 175967 times.
✓ Branch 1 taken 565893635 times.
566069602 if(ispitfall(c)) return c;
2158 565893635 return 0;
2159 575457040 }
2160 50 optional<combined_handle_t> get_pitfall_handle(int32_t x, int32_t y) //Return the highest-layer active pit combo handle at the given position
2161 {
2162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if(int32_t c = MAPFFCOMBO(x,y))
2163 {
2164 return ispitfall(c) ? getFFCAt(x,y) : nullopt;
2165 }
2166 50 int32_t c = MAPCOMBOL(2,x,y);
2167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if(ispitfall(c)) return get_rpos_handle_for_world_xy(x, y, 2);
2168
2169
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 44 times.
50 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2170 {
2171
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1))
2172 return nullopt;
2173 6 }
2174 else
2175 {
2176
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
44 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1))
2177 return nullopt;
2178 }
2179 50 c = MAPCOMBOL(1,x,y);
2180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if(ispitfall(c)) return get_rpos_handle_for_world_xy(x, y, 1);
2181
2182
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 44 times.
50 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2183 {
2184
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,0))
2185 return nullopt;
2186 6 }
2187 else
2188 {
2189
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
44 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,0))
2190 return nullopt;
2191 }
2192 50 c = MAPCOMBO(x,y);
2193
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 if(ispitfall(c)) return get_rpos_handle_for_world_xy(x, y, 0);
2194 return nullopt;
2195 50 }
2196 5324886 bool check_icy(newcombo const& cmb, int type)
2197 {
2198
1/2
✓ Branch 0 taken 5324886 times.
✗ Branch 1 not taken.
5324886 if(cmb.type != cICY)
2199 5324886 return false;
2200 switch(type)
2201 {
2202 case ICY_BLOCK:
2203 return cmb.usrflags&cflag1;
2204 case ICY_PLAYER:
2205 return cmb.usrflags&cflag2;
2206 }
2207 return false;
2208 5324886 }
2209 1775509 int get_icy(int x, int y, int type)
2210 {
2211 1775509 int32_t c = MAPCOMBOL(2,x,y);
2212
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1775509 times.
1775509 if(check_icy(combobuf[c], type)) return c;
2213
2214 1775509 int screen = get_screen_for_world_xy(x, y);
2215
2216 1775509 mapscr* scr = get_scr_layer_valid(screen, 2);
2217
2/2
✓ Branch 0 taken 430747 times.
✓ Branch 1 taken 1344762 times.
1775509 if (scr)
2218 {
2219
2/2
✓ Branch 0 taken 515 times.
✓ Branch 1 taken 1344247 times.
1344762 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2220 {
2221
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 515 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
515 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1, scr)) return 0;
2222 515 }
2223 else
2224 {
2225
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1344247 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1344247 if (combobuf[MAPCOMBO2(1,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1, scr)) return 0;
2226 }
2227 1344762 }
2228 1775509 c = MAPCOMBOL(1,x,y);
2229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1775509 times.
1775509 if(check_icy(combobuf[c], type)) return c;
2230
2231 1775509 scr = get_scr_layer_valid(screen, 1);
2232
2/2
✓ Branch 0 taken 73589 times.
✓ Branch 1 taken 1701920 times.
1775509 if (scr)
2233 {
2234
2/2
✓ Branch 0 taken 1934 times.
✓ Branch 1 taken 1699986 times.
1701920 if (get_qr(qr_OLD_BRIDGE_COMBOS))
2235 {
2236
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1934 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1934 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && !_walkflag_layer(x,y,1, scr)) return 0;
2237 1934 }
2238 else
2239 {
2240
3/4
✓ Branch 0 taken 1641 times.
✓ Branch 1 taken 1698345 times.
✓ Branch 2 taken 1641 times.
✗ Branch 3 not taken.
1699986 if (combobuf[MAPCOMBO2(0,x,y)].type == cBRIDGE && _effectflag_layer(x,y,1, scr)) return 0;
2241 }
2242 1700279 }
2243 1773868 c = MAPCOMBO(x,y);
2244
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1773868 times.
1773868 if(check_icy(combobuf[c], type)) return c;
2245 1773868 return 0;
2246 1775509 }
2247
2248 12777044 static bool checkSV(int32_t x, int32_t y, int32_t flag)
2249 {
2250
8/8
✓ Branch 0 taken 12770246 times.
✓ Branch 1 taken 6798 times.
✓ Branch 2 taken 12761380 times.
✓ Branch 3 taken 8866 times.
✓ Branch 4 taken 12749748 times.
✓ Branch 5 taken 11632 times.
✓ Branch 6 taken 427844 times.
✓ Branch 7 taken 12321904 times.
12777044 if(x<0 || x>=world_w || y<0 || y>=world_h)
2251 455140 return false;
2252
2253 12321904 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, 0);
2254
2/4
✓ Branch 0 taken 12321904 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12321904 times.
12321904 if (rpos_handle.sflag() == flag || rpos_handle.cflag() == flag)
2255 return true;
2256
2257 12321904 change_rpos_handle_layer(rpos_handle, 1);
2258
2/2
✓ Branch 0 taken 7322474 times.
✓ Branch 1 taken 4999430 times.
12321904 if (rpos_handle.scr->is_valid())
2259
2/4
✓ Branch 0 taken 4999430 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4999430 times.
4999430 if (rpos_handle.sflag() == flag || rpos_handle.cflag() == flag)
2260 return true;
2261
2262 12321904 change_rpos_handle_layer(rpos_handle, 2);
2263
2/2
✓ Branch 0 taken 10659640 times.
✓ Branch 1 taken 1662264 times.
12321904 if (rpos_handle.scr->is_valid())
2264
2/4
✓ Branch 0 taken 1662264 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1662264 times.
1662264 if (rpos_handle.sflag() == flag || rpos_handle.cflag() == flag)
2265 return true;
2266
2267 12321904 return false;
2268 12777044 }
2269
2270 6451428 bool isSVLadder(int32_t x, int32_t y)
2271 {
2272 6451428 return checkSV(x, y, mfSIDEVIEWLADDER);
2273 }
2274
2275 6325616 bool isSVPlatform(int32_t x, int32_t y)
2276 {
2277 6325616 return checkSV(x, y, mfSIDEVIEWPLATFORM);
2278 }
2279
2280 6325616 bool checkSVLadderPlatform(int32_t x, int32_t y)
2281 {
2282
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6325616 times.
✓ Branch 2 taken 6325616 times.
✗ Branch 3 not taken.
6325616 return isSVPlatform(x,y) || (isSVLadder(x,y) && !isSVLadder(x,y-16));
2283 }
2284
2285 1612 bool isstepable(int32_t combo) //can use ladder on it
2286 {
2287
2/2
✓ Branch 0 taken 1606 times.
✓ Branch 1 taken 6 times.
1612 if(combo_class_buf[combobuf[combo].type].ladder_pass) return true;
2288
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(combo_class_buf[combobuf[combo].type].pit)
2289 {
2290 if(combobuf[combo].usrflags&cflag4)
2291 {
2292 int32_t ldrid = current_item_id(itype_ladder);
2293 return (ldrid > -1 && itemsbuf[ldrid].flags & item_flag1);
2294 }
2295 }
2296 6 return false;
2297 1612 }
2298
2299 32256 bool isHSGrabbable(newcombo const& cmb)
2300 {
2301
2/2
✓ Branch 0 taken 367 times.
✓ Branch 1 taken 31889 times.
32256 if(cmb.type == cHSGRAB) return true;
2302 31889 return cmb.genflags & cflag1;
2303 32256 }
2304
2305 954 bool isSwitchHookable(newcombo const& cmb)
2306 {
2307
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 822 times.
954 if(cmb.type == cSWITCHHOOK) return true;
2308 822 return cmb.genflags & cflag2;
2309 954 }
2310
2311 60877 bool check_hshot(int32_t layer, int32_t x, int32_t y, bool switchhook, rpos_t *out_rpos, ffcdata **out_ffc)
2312 {
2313 60877 rpos_t cpos = rpos_t::None;
2314
2/2
✓ Branch 0 taken 63556 times.
✓ Branch 1 taken 124433 times.
60877 if(out_rpos)
2315 {
2316 124433 int32_t id = MAPCOMBO2(layer-1,x,y);
2317
2/2
✓ Branch 0 taken 28634 times.
✓ Branch 1 taken 95799 times.
124433 if(id > 0)
2318 {
2319 95799 newcombo const& cmb = combobuf[id];
2320
4/4
✓ Branch 0 taken 32214 times.
✓ Branch 1 taken 63585 times.
✓ Branch 2 taken 31778 times.
✓ Branch 3 taken 31807 times.
95799 cpos = (switchhook ? isSwitchHookable(cmb) : isHSGrabbable(cmb)) ? COMBOPOS_REGION(x,y) : rpos_t::None;
2321 32243 }
2322 60877 }
2323
2324 124433 ffcdata* ffc = nullptr;
2325
4/4
✓ Branch 0 taken 27865 times.
✓ Branch 1 taken 96568 times.
✓ Branch 2 taken 24472 times.
✓ Branch 3 taken 3393 times.
124433 if (out_ffc && !get_qr(qr_OLD_FFC_FUNCTIONALITY))
2326 {
2327 10359 for_some_ffcs([&](const ffc_handle_t& ffc_handle) {
2328
2/2
✓ Branch 0 taken 6853 times.
✓ Branch 1 taken 113 times.
6966 if (ffcIsAt(ffc_handle, x, y))
2329 {
2330 113 auto& cmb = ffc_handle.combo();
2331
4/4
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 71 times.
✓ Branch 2 taken 35 times.
✓ Branch 3 taken 36 times.
113 if (switchhook ? isSwitchHookable(cmb) : isHSGrabbable(cmb))
2332 {
2333 77 ffc = ffc_handle.ffc;
2334 77 return false;
2335 }
2336 36 }
2337 6889 return true;
2338 6896 });
2339 3393 }
2340
2341
4/4
✓ Branch 0 taken 60877 times.
✓ Branch 1 taken 63556 times.
✓ Branch 2 taken 436 times.
✓ Branch 3 taken 60441 times.
124433 if (out_rpos && cpos != rpos_t::None) *out_rpos = cpos;
2342
4/4
✓ Branch 0 taken 27865 times.
✓ Branch 1 taken 96568 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 27858 times.
124433 if (out_ffc && ffc) *out_ffc = ffc;
2343
2/2
✓ Branch 0 taken 63992 times.
✓ Branch 1 taken 60441 times.
124433 return (cpos != rpos_t::None || ffc);
2344 }
2345
2346 5034 bool ishookshottable(int32_t bx, int32_t by)
2347 {
2348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5034 times.
5034 if(!_walkflag(bx,by,1))
2349 return true;
2350
2351
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 5026 times.
5034 if (collide_object(bx, by, 1, 1))
2352 8 return false;
2353
2354 5026 bool ret = true;
2355
2/2
✓ Branch 0 taken 15078 times.
✓ Branch 1 taken 1883 times.
16961 for(int32_t i=2; i>=0; i--)
2356 {
2357 15078 int32_t c = MAPCOMBO2(i-1,bx,by);
2358 15078 int32_t t = combobuf[c].type;
2359
2360
6/6
✓ Branch 0 taken 5026 times.
✓ Branch 1 taken 10052 times.
✓ Branch 2 taken 3692 times.
✓ Branch 3 taken 1334 times.
✓ Branch 4 taken 1883 times.
✓ Branch 5 taken 1809 times.
15078 if(i == 0 && (t == cHOOKSHOTONLY || t == cLADDERHOOKSHOT)) return true;
2361
2362
3/4
✓ Branch 0 taken 10982 times.
✓ Branch 1 taken 953 times.
✓ Branch 2 taken 953 times.
✗ Branch 3 not taken.
12888 bool dried = (iswater_type(t) && DRIEDLAKE);
2363
2364 11935 int32_t b=1;
2365
2366
2/2
✓ Branch 0 taken 5956 times.
✓ Branch 1 taken 5979 times.
11935 if(bx&8) b<<=2;
2367
2368
2/2
✓ Branch 0 taken 3779 times.
✓ Branch 1 taken 8156 times.
11935 if(by&8) b<<=1;
2369
2370
7/8
✓ Branch 0 taken 2055 times.
✓ Branch 1 taken 9880 times.
✓ Branch 2 taken 2055 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1093 times.
✓ Branch 5 taken 962 times.
✓ Branch 6 taken 75 times.
✓ Branch 7 taken 887 times.
11935 if(combobuf[c].walk&b && !dried && !(combo_class_buf[t].ladder_pass && t!=cLADDERONLY) && t!=cHOOKSHOTONLY)
2371 887 ret = false;
2372 11935 }
2373
2374 1883 return ret;
2375 5034 }
2376
2377 10082 bool reveal_hidden_stairs(mapscr *s, int32_t screen, bool redraw)
2378 {
2379
4/4
✓ Branch 0 taken 9505 times.
✓ Branch 1 taken 577 times.
✓ Branch 2 taken 9505 times.
✓ Branch 3 taken 577 times.
10082 if((s->stairx || s->stairy) && s->secretcombo[sSTAIRS])
2380 {
2381 577 int pos = COMBOPOS(s->stairx,s->stairy);
2382 577 s->data[pos] = s->secretcombo[sSTAIRS];
2383 577 s->cset[pos] = s->secretcset[sSTAIRS];
2384 577 s->sflag[pos] = s->secretflag[sSTAIRS];
2385
2386
2/2
✓ Branch 0 taken 254 times.
✓ Branch 1 taken 323 times.
577 if (redraw)
2387 {
2388 762 auto [x, y] = translate_screen_coordinates_to_world(screen, s->stairx, s->stairy);
2389 762 putcombo(scrollbuf,x,y,s->data[pos],s->cset[pos]);
2390 254 }
2391
2392 577 return true;
2393 }
2394
2395 9505 return false;
2396 10082 }
2397
2398 51093 screen_handles_t create_screen_handles_one(mapscr* base_scr)
2399 {
2400 DCHECK(base_scr->is_valid());
2401
2402 51093 screen_handles_t screen_handles{};
2403 51093 screen_handles[0] = {base_scr, base_scr, base_scr->screen, 0};
2404 51093 return screen_handles;
2405 }
2406
2407 55460626 screen_handles_t create_screen_handles(mapscr* base_scr)
2408 {
2409 DCHECK(get_scr(base_scr->screen) == base_scr);
2410 DCHECK(base_scr->is_valid());
2411
2412 55460626 int screen = base_scr->screen;
2413 screen_handles_t screen_handles;
2414 55460626 screen_handles[0] = {base_scr, base_scr, screen, 0};
2415
2/2
✓ Branch 0 taken 332763756 times.
✓ Branch 1 taken 55460626 times.
388224382 for (int i = 1; i <= 6; i++)
2416 332763756 screen_handles[i] = {base_scr, get_scr_layer_valid(screen, i), screen, i};
2417 55460626 return screen_handles;
2418 }
2419
2420 106198 bool remove_screenstatecombos2(const screen_handles_t& screen_handles, bool do_layers, int32_t what1, int32_t what2)
2421 {
2422 106198 mapscr* scr = screen_handles[0].scr;
2423 106198 bool didit=false;
2424
2425
2/2
✓ Branch 0 taken 106198 times.
✓ Branch 1 taken 18690848 times.
18797046 for(int32_t i=0; i<176; i++)
2426 {
2427 18690848 newcombo const& cmb = combobuf[scr->data[i]];
2428
2/2
✓ Branch 0 taken 326 times.
✓ Branch 1 taken 18690522 times.
18690848 if(cmb.usrflags&cflag16) continue; //custom state instead of normal state
2429
4/4
✓ Branch 0 taken 18688993 times.
✓ Branch 1 taken 1529 times.
✓ Branch 2 taken 1102 times.
✓ Branch 3 taken 18687891 times.
18690522 if((cmb.type == what1) || (cmb.type== what2))
2430 {
2431 2631 scr->data[i]++;
2432 2631 didit=true;
2433 2631 }
2434 18690522 }
2435
2436
2/2
✓ Branch 0 taken 92 times.
✓ Branch 1 taken 106106 times.
106198 if (do_layers)
2437 {
2438
2/2
✓ Branch 0 taken 636636 times.
✓ Branch 1 taken 106106 times.
742742 for(int32_t j=1; j<=6; j++)
2439 {
2440 636636 mapscr* layer_scr = screen_handles[j].scr;
2441
2/2
✓ Branch 0 taken 173044 times.
✓ Branch 1 taken 463592 times.
636636 if (!layer_scr) continue;
2442
2443
2/2
✓ Branch 0 taken 30455744 times.
✓ Branch 1 taken 173044 times.
30628788 for(int32_t i=0; i<176; i++)
2444 {
2445 30455744 newcombo const& cmb = combobuf[layer_scr->data[i]];
2446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 30455744 times.
30455744 if(cmb.usrflags&cflag16) continue; //custom state instead of normal state
2447
4/4
✓ Branch 0 taken 30455661 times.
✓ Branch 1 taken 83 times.
✓ Branch 2 taken 265 times.
✓ Branch 3 taken 30455396 times.
30455744 if((cmb.type== what1) || (cmb.type== what2))
2448 {
2449 348 layer_scr->data[i]++;
2450 348 didit=true;
2451 348 }
2452 30455744 }
2453 173044 }
2454 106106 }
2455
2456 // 'do_layers' also means that this is called on an active temp screen, so update its ffcs.
2457
3/4
✓ Branch 0 taken 20406 times.
✓ Branch 1 taken 85792 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 20406 times.
106198 if (!get_qr(qr_OLD_FFC_FUNCTIONALITY) && do_layers)
2458 {
2459 20406 word c = scr->numFFC();
2460
2/2
✓ Branch 0 taken 73350 times.
✓ Branch 1 taken 20406 times.
93756 for(word i=0; i<c; i++)
2461 {
2462 73350 ffcdata* ffc = &scr->ffcs[i];
2463 73350 newcombo const& cmb = combobuf[ffc->data];
2464
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 73350 times.
73350 if(cmb.usrflags&cflag16) continue; //custom state instead of normal state
2465
2/4
✓ Branch 0 taken 73350 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 73350 times.
73350 if((cmb.type== what1) || (cmb.type== what2))
2466 {
2467 zc_ffc_modify(*ffc, 1);
2468 didit=true;
2469 }
2470 73350 }
2471 20406 }
2472
2473 106198 return didit;
2474 }
2475
2476 14 bool remove_xstatecombos(const screen_handles_t& screen_handles, byte xflag, bool triggers)
2477 {
2478 14 int screen = screen_handles[0].scr->screen;
2479
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2480 14 return remove_xstatecombos_mi(screen_handles, mi, xflag, triggers);
2481 }
2482 462496142 bool remove_xstatecombos_mi(const screen_handles_t& screen_handles, int32_t mi, byte xflag, bool triggers)
2483 {
2484 462496142 bool didit=false;
2485
2/2
✓ Branch 0 taken 462471649 times.
✓ Branch 1 taken 24493 times.
462496142 if(!getxmapflag_mi(mi, 1<<xflag)) return false;
2486
2487 24493 mapscr* s = screen_handles[0].scr;
2488 24493 int screen = s->screen;
2489 24493 bool is_active_screen = is_in_current_region(s);
2490
2491 21171069 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
2492
4/4
✓ Branch 0 taken 21134960 times.
✓ Branch 1 taken 11616 times.
✓ Branch 2 taken 21133233 times.
✓ Branch 3 taken 1727 times.
21146576 if(triggers && force_ex_trigger_any(rpos_handle, xflag))
2493 1727 didit = true;
2494
2/2
✓ Branch 0 taken 63627 times.
✓ Branch 1 taken 21081222 times.
21144849 else switch (rpos_handle.ctype())
2495 {
2496 case cLOCKBLOCK: case cLOCKBLOCK2:
2497 case cBOSSLOCKBLOCK: case cBOSSLOCKBLOCK2:
2498 case cCHEST: case cCHEST2:
2499 case cLOCKEDCHEST: case cLOCKEDCHEST2:
2500 case cBOSSCHEST: case cBOSSCHEST2:
2501 {
2502 63627 auto& cmb = rpos_handle.combo();
2503
2/2
✓ Branch 0 taken 62059 times.
✓ Branch 1 taken 1568 times.
63627 if(!(cmb.usrflags&cflag16)) return; //custom state instead of normal state
2504
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 62030 times.
62059 if(cmb.attribytes[5] == xflag)
2505 {
2506 29 rpos_handle.increment_data();
2507 29 didit=true;
2508 29 }
2509 62059 break;
2510 }
2511 }
2512 21146576 });
2513
2514
4/4
✓ Branch 0 taken 24452 times.
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 14832 times.
✓ Branch 3 taken 9620 times.
24493 if (is_active_screen && !get_qr(qr_OLD_FFC_FUNCTIONALITY))
2515 {
2516 14832 word c = s->numFFC();
2517 14832 int screen_index_offset = get_region_screen_offset(screen);
2518
2/2
✓ Branch 0 taken 36840 times.
✓ Branch 1 taken 14832 times.
51672 for (uint8_t i = 0; i < c; i++)
2519 {
2520 36840 auto ffc_handle = *s->getFFCHandle(i, screen_index_offset);
2521 36840 auto& cmb = ffc_handle.combo();
2522
3/4
✓ Branch 0 taken 36840 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36824 times.
✓ Branch 3 taken 16 times.
36840 if(triggers && force_ex_trigger_ffc_any(ffc_handle, xflag))
2523 16 didit = true;
2524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36824 times.
36824 else switch(cmb.type)
2525 {
2526 case cLOCKBLOCK: case cLOCKBLOCK2:
2527 case cBOSSLOCKBLOCK: case cBOSSLOCKBLOCK2:
2528 case cCHEST: case cCHEST2:
2529 case cLOCKEDCHEST: case cLOCKEDCHEST2:
2530 case cBOSSCHEST: case cBOSSCHEST2:
2531 {
2532 if(!(cmb.usrflags&cflag16)) continue; //custom state instead of normal state
2533 if(cmb.attribytes[5] == xflag)
2534 {
2535 zc_ffc_modify(*ffc_handle.ffc, 1);
2536 didit=true;
2537 }
2538 break;
2539 }
2540 }
2541 36840 }
2542 14832 }
2543
2544 24493 return didit;
2545 462496142 }
2546
2547 14401681 void clear_xstatecombos(const screen_handles_t& screen_handles, bool triggers)
2548 {
2549 14401681 int screen = screen_handles[0].screen;
2550
2/2
✓ Branch 0 taken 387833 times.
✓ Branch 1 taken 14013848 times.
14401681 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2551 14401681 clear_xstatecombos_mi(screen_handles, mi, triggers);
2552 14401681 }
2553
2554 14453004 void clear_xstatecombos_mi(const screen_handles_t& screen_handles, int32_t mi, bool triggers)
2555 {
2556
2/2
✓ Branch 0 taken 462496128 times.
✓ Branch 1 taken 14453004 times.
476949132 for (int q = 0; q < 32; ++q)
2557 {
2558 462496128 remove_xstatecombos_mi(screen_handles, mi, q, triggers);
2559 462496128 }
2560 14453004 }
2561
2562 bool remove_xdoors(const screen_handles_t& screen_handles, uint dir, uint ind, bool triggers)
2563 {
2564 int screen = screen_handles[0].screen;
2565 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2566 return remove_xdoors_mi(screen_handles, mi, dir, ind, triggers);
2567 }
2568 462496128 bool remove_xdoors_mi(const screen_handles_t& screen_handles, int32_t mi, uint dir, uint ind, bool triggers)
2569 {
2570 462496128 bool didit=false;
2571
1/2
✓ Branch 0 taken 462496128 times.
✗ Branch 1 not taken.
462496128 if (!getxdoor_mi(mi, dir, ind)) return false;
2572
2573 mapscr* scr = screen_handles[0].scr;
2574 int screen = scr->screen;
2575 bool is_active_screen = is_in_current_region(scr);
2576
2577 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
2578 if (triggers && force_ex_door_trigger_any(rpos_handle, dir, ind))
2579 didit = true;
2580 else; //future door combo types?
2581 });
2582
2583 if (!get_qr(qr_OLD_FFC_FUNCTIONALITY) && is_active_screen)
2584 {
2585 word c = scr->numFFC();
2586 int screen_index_offset = get_region_screen_offset(screen);
2587 for (uint8_t i = 0; i < c; i++)
2588 {
2589 auto ffc_handle = *scr->getFFCHandle(i, screen_index_offset);
2590 if (triggers && force_ex_door_trigger_ffc_any(ffc_handle, dir, ind))
2591 didit = true;
2592 else; //future door combo types?
2593 }
2594 }
2595
2596 return didit;
2597 462496128 }
2598
2599 14401681 void clear_xdoors(const screen_handles_t& screen_handles, bool triggers)
2600 {
2601 14401681 int screen = screen_handles[0].screen;
2602
2/2
✓ Branch 0 taken 387833 times.
✓ Branch 1 taken 14013848 times.
14401681 int mi = mapind(cur_map, screen >= 0x80 ? home_screen : screen);
2603 14401681 return clear_xdoors_mi(screen_handles, mi, triggers);
2604 }
2605
2606 14453004 void clear_xdoors_mi(const screen_handles_t& screen_handles, int32_t mi, bool triggers)
2607 {
2608
2/2
✓ Branch 0 taken 57812016 times.
✓ Branch 1 taken 14453004 times.
72265020 for (int dir = 0; dir < 4; ++dir)
2609
2/2
✓ Branch 0 taken 462496128 times.
✓ Branch 1 taken 57812016 times.
520308144 for (int q = 0; q < 8; ++q)
2610 520308144 remove_xdoors_mi(screen_handles, mi, dir, q, triggers);
2611 14453004 }
2612
2613 759 bool remove_lockblocks(const screen_handles_t& screen_handles)
2614 {
2615 759 return remove_screenstatecombos2(screen_handles, true, cLOCKBLOCK, cLOCKBLOCK2);
2616 }
2617
2618 98 bool remove_bosslockblocks(const screen_handles_t& screen_handles)
2619 {
2620 98 return remove_screenstatecombos2(screen_handles, true, cBOSSLOCKBLOCK, cBOSSLOCKBLOCK2);
2621 }
2622
2623 76553 bool remove_chests(const screen_handles_t& screen_handles)
2624 {
2625 76553 return remove_screenstatecombos2(screen_handles, true, cCHEST, cCHEST2);
2626 }
2627
2628 2484 bool remove_lockedchests(const screen_handles_t& screen_handles)
2629 {
2630 2484 return remove_screenstatecombos2(screen_handles, true, cLOCKEDCHEST, cLOCKEDCHEST2);
2631 }
2632
2633 26212 bool remove_bosschests(const screen_handles_t& screen_handles)
2634 {
2635 26212 return remove_screenstatecombos2(screen_handles, true, cBOSSCHEST, cBOSSCHEST2);
2636 }
2637
2638 1384047 void delete_fireball_shooter(const rpos_handle_t& rpos_handle)
2639 {
2640 1384047 int32_t ct=rpos_handle.ctype();
2641
2642
6/6
✓ Branch 0 taken 1383427 times.
✓ Branch 1 taken 620 times.
✓ Branch 2 taken 1383175 times.
✓ Branch 3 taken 252 times.
✓ Branch 4 taken 1383067 times.
✓ Branch 5 taken 108 times.
1384047 if(ct!=cL_STATUE && ct!=cR_STATUE && ct!=cC_STATUE)
2643 1383067 return;
2644
2645 2465 auto [cx, cy] = rpos_handle.xy();
2646
3/4
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 620 times.
✓ Branch 3 taken 108 times.
980 switch(ct)
2647 {
2648 case cL_STATUE:
2649 620 cx += 4;
2650 620 cy += 7;
2651 620 break;
2652
2653 case cR_STATUE:
2654 252 cx -= 8;
2655 252 cy -= 1;
2656 252 break;
2657
2658 case cC_STATUE:
2659 108 break;
2660 }
2661
2662
2/2
✓ Branch 0 taken 980 times.
✓ Branch 1 taken 1485 times.
2465 for(int32_t j=0; j<guys.Count(); j++)
2663 {
2664 // Finds the smallest enemy ID
2665
9/10
✓ Branch 0 taken 399 times.
✓ Branch 1 taken 1086 times.
✓ Branch 2 taken 399 times.
✓ Branch 3 taken 1086 times.
✓ Branch 4 taken 346 times.
✓ Branch 5 taken 53 times.
✓ Branch 6 taken 346 times.
✓ Branch 7 taken 53 times.
✓ Branch 8 taken 346 times.
✗ Branch 9 not taken.
2970 if((int32_t(guys.spr(j)->x)==cx)&&(int32_t(guys.spr(j)->y)==cy)&&(guysbuf[(guys.spr(j)->id)&0xFFF].flags & guy_fire))
2666 {
2667 346 guys.del(j);
2668 346 }
2669 1485 }
2670 1384047 }
2671
2672 15 static int32_t findtrigger(int32_t screen)
2673 {
2674 15 int32_t checkflag=0;
2675 15 int32_t ret = 0;
2676
2677 mapscr* screens[7];
2678
2/2
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 15 times.
120 for (int32_t j = 0; j <= 6; j++)
2679 {
2680 105 screens[j] = get_scr_layer_valid(screen, j);
2681 105 }
2682
2683 15 bool sflag = false;
2684
2/2
✓ Branch 0 taken 2640 times.
✓ Branch 1 taken 15 times.
2655 for(word j=0; j<176; j++)
2685 {
2686
2/2
✓ Branch 0 taken 26752 times.
✓ Branch 1 taken 2640 times.
29392 for(int32_t layer = -1; layer < 6; ++layer)
2687 {
2688 26752 mapscr* scr = screens[layer+1];
2689
2/2
✓ Branch 0 taken 16544 times.
✓ Branch 1 taken 10208 times.
26752 if (!scr) continue;
2690
2691
2/2
✓ Branch 0 taken 8272 times.
✓ Branch 1 taken 8272 times.
16544 if(sflag)
2692 8272 checkflag = scr->sflag[j];
2693 else
2694 8272 checkflag = combobuf[scr->data[j]].flag;
2695 16544 sflag = !sflag;
2696
2/2
✓ Branch 0 taken 8272 times.
✓ Branch 1 taken 8272 times.
16544 if (sflag) --layer;
2697
2698
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 16534 times.
16544 switch(checkflag)
2699 {
2700 case mfANYFIRE:
2701 case mfSTRONGFIRE:
2702 case mfMAGICFIRE:
2703 case mfDIVINEFIRE:
2704 case mfARROW:
2705 case mfSARROW:
2706 case mfGARROW:
2707 case mfSBOMB:
2708 case mfBOMB:
2709 case mfBRANG:
2710 case mfMBRANG:
2711 case mfFBRANG:
2712 case mfWANDMAGIC:
2713 case mfREFMAGIC:
2714 case mfREFFIREBALL:
2715 case mfSWORD:
2716 case mfWSWORD:
2717 case mfMSWORD:
2718 case mfXSWORD:
2719 case mfSWORDBEAM:
2720 case mfWSWORDBEAM:
2721 case mfMSWORDBEAM:
2722 case mfXSWORDBEAM:
2723 case mfHOOKSHOT:
2724 case mfWAND:
2725 case mfHAMMER:
2726 case mfSTRIKE:
2727 10 ret += 1;
2728 10 break;
2729 }
2730 16544 }
2731 2640 }
2732
2733 15 return ret;
2734 }
2735
2736 11688 static void log_trigger_secret_reason(TriggerSource source)
2737 {
2738
2/2
✓ Branch 0 taken 439 times.
✓ Branch 1 taken 11249 times.
11688 if (source == TriggerSource::Singular)
2739 {
2740 439 Z_eventlog("Restricted Screen Secrets triggered\n");
2741 439 }
2742 else
2743 {
2744 11249 const char* source_str = "";
2745
7/12
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 7141 times.
✓ Branch 3 taken 847 times.
✓ Branch 4 taken 2732 times.
✓ Branch 5 taken 475 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 49 times.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
11249 switch (source)
2746 {
2747 case TriggerSource::Singular: break;
2748 7141 case TriggerSource::Unspecified: source_str = "unspecified means"; break;
2749 847 case TriggerSource::EnemiesScreenFlag: source_str = "the 'Enemies->Secret' screen flag"; break;
2750 2732 case TriggerSource::SecretsScreenState: source_str = "the 'Secrets' screen state"; break;
2751 475 case TriggerSource::Script: source_str = "a script"; break;
2752 1 case TriggerSource::ItemsSecret: source_str = "Items->Secrets"; break;
2753 49 case TriggerSource::GenericCombo: source_str = "Generic Combo"; break;
2754 4 case TriggerSource::LightTrigger: source_str = "Light Triggers"; break;
2755 case TriggerSource::SCC: source_str = "SCC"; break;
2756 case TriggerSource::CheatTemp: source_str = "Cheat (Temp)"; break;
2757 case TriggerSource::CheatPerm: source_str = "Cheat (Perm)"; break;
2758 }
2759 11249 Z_eventlog("Screen Secrets triggered by %s\n", source_str);
2760 }
2761 11688 }
2762
2763 // single:
2764 // >-1 : the singular triggering combo
2765 // -1: triggered by some other cause
2766 11480 void trigger_secrets_for_screen(TriggerSource source, mapscr* scr, bool high16only, int32_t single)
2767 {
2768 11480 log_trigger_secret_reason(source);
2769
2/2
✓ Branch 0 taken 439 times.
✓ Branch 1 taken 11041 times.
11480 if (single < 0)
2770 11041 get_screen_state(scr->screen).triggered_secrets = true;
2771
2772 11480 bool do_replay_comment = true;
2773 11480 bool from_active_screen = true;
2774 11480 trigger_secrets_for_screen_internal(create_screen_handles(scr), from_active_screen, high16only, single, do_replay_comment);
2775
2776 // Respect secret state carryovers for active screens.
2777
2/2
✓ Branch 0 taken 439 times.
✓ Branch 1 taken 11041 times.
11480 if (single >= 0) return;
2778 11041 int flag = mSECRET;
2779 11041 int cmap = scr->map;
2780 11041 int cscr = scr->screen;
2781 11041 int nmap=TheMaps[((cmap)*MAPSCRS)+cscr].nextmap;
2782 11041 int nscr=TheMaps[((cmap)*MAPSCRS)+cscr].nextscr;
2783
2784 11041 std::vector<int32_t> done;
2785
2/2
✓ Branch 0 taken 10854 times.
✓ Branch 1 taken 187 times.
11041 bool looped = (nmap==cmap+1 && nscr==cscr);
2786
2787
6/6
✓ Branch 0 taken 629 times.
✓ Branch 1 taken 10964 times.
✓ Branch 2 taken 77 times.
✓ Branch 3 taken 552 times.
✓ Branch 4 taken 552 times.
✓ Branch 5 taken 11041 times.
11593 while((nmap!=0) && !looped && !(nscr>=128))
2788 {
2789
9/10
✓ Branch 0 taken 385 times.
✓ Branch 1 taken 167 times.
✓ Branch 2 taken 84 times.
✓ Branch 3 taken 301 times.
✓ Branch 4 taken 74 times.
✓ Branch 5 taken 10 times.
✓ Branch 6 taken 74 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 70 times.
552 if (nmap - 1 == cur_map && is_in_current_region(nscr) && (scr->nocarry&flag)!=flag && !get_screen_state(nscr).triggered_secrets)
2790 {
2791
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 log_trigger_secret_reason(TriggerSource::SecretsScreenState);
2792
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
4 trigger_secrets_for_screen_internal(create_screen_handles(get_scr(nscr)), from_active_screen, high16only, single, do_replay_comment);
2793
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 get_screen_state(nscr).triggered_secrets = true;
2794 4 }
2795
2796 552 cmap=nmap;
2797 552 cscr=nscr;
2798 552 nmap=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextmap;
2799 552 nscr=TheMaps[((cmap-1)*MAPSCRS)+cscr].nextscr;
2800
2801
2/2
✓ Branch 0 taken 1101 times.
✓ Branch 1 taken 552 times.
1653 for(auto it = done.begin(); it != done.end(); it++)
2802 {
2803
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 77 times.
1101 if(*it == ((nmap-1)<<7)+nscr)
2804 77 looped = true;
2805 1101 }
2806
2807
1/2
✓ Branch 0 taken 552 times.
✗ Branch 1 not taken.
552 done.push_back(((nmap-1)<<7)+nscr);
2808 }
2809 11480 }
2810
2811 2422 void trigger_secrets_for_screen(TriggerSource source, int32_t screen, bool high16only, int32_t single)
2812 {
2813 2422 trigger_secrets_for_screen(source, get_scr(screen), high16only, single);
2814 2422 }
2815
2816 17953 void trigger_secrets_for_screen_internal(const screen_handles_t& screen_handles, bool from_active_screen, bool high16only, int32_t single, bool do_replay_comment)
2817 {
2818 17953 mapscr* scr = screen_handles[0].scr;
2819 17953 int screen = scr->screen;
2820
2821 // TODO(replays): No real reason for "do_replay_comment" to exist - I just did not want to update many replays when fixing
2822 // slopes in sideview mode (which required loading nearby screens in loadscr).
2823 // TODO(replays): This should just use `screen`.
2824
3/4
✓ Branch 0 taken 17953 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 535 times.
✓ Branch 3 taken 17418 times.
17953 if (replay_is_active() && do_replay_comment)
2825
4/6
✓ Branch 0 taken 11484 times.
✓ Branch 1 taken 5934 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11484 times.
✓ Branch 4 taken 17418 times.
✗ Branch 5 not taken.
17418 replay_step_comment(fmt::format("trigger secrets scr={}", from_active_screen && scr != special_warp_return_scr ? screen : cur_screen));
2826
2827
2/2
✓ Branch 0 taken 6469 times.
✓ Branch 1 taken 11484 times.
17953 if (from_active_screen)
2828 {
2829 5427284 for_every_combo_in_screen(screen_handles, [&](const auto& handle) {
2830 5415800 auto cid = handle.data();
2831 5415800 auto& cmb = handle.combo();
2832
4/4
✓ Branch 0 taken 5414092 times.
✓ Branch 1 taken 229446 times.
✓ Branch 2 taken 1688 times.
✓ Branch 3 taken 182 times.
5645408 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
2833 {
2834 229628 auto& trig = cmb.triggers[idx];
2835
3/4
✓ Branch 0 taken 65534 times.
✓ Branch 1 taken 163912 times.
✓ Branch 2 taken 182 times.
✗ Branch 3 not taken.
229628 if (trig.triggerflags[2] & combotriggerSECRETSTR)
2836 {
2837 163912 do_trigger_combo(handle, idx, ctrigSECRETS);
2838
2/4
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 163892 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
163912 if(handle.data() != cid) break;
2839 163892 }
2840 229608 }
2841 5415800 });
2842 11484 }
2843
2844 17953 int32_t ft=0; //Flag trigger?
2845 17953 int32_t msflag=0; // Misc. secret flag
2846
2847
2/2
✓ Branch 0 taken 3159728 times.
✓ Branch 1 taken 17953 times.
3177681 for(int32_t i=0; i<176; i++) //Do the 'trigger flags' (non 16-31)
2848 {
2849
4/4
✓ Branch 0 taken 77264 times.
✓ Branch 1 taken 3082464 times.
✓ Branch 2 taken 439 times.
✓ Branch 3 taken 76825 times.
3159728 if(single>=0 && i!=single) continue; //If it's got a singular flag and i isn't where the flag is
2850
2851 // Remember the misc. secret flag; if triggered, use this instead
2852
4/4
✓ Branch 0 taken 114157 times.
✓ Branch 1 taken 2968746 times.
✓ Branch 2 taken 49375 times.
✓ Branch 3 taken 64782 times.
3082903 if(scr->sflag[i]>=mfSECRETS01 && scr->sflag[i]<=mfSECRETS16)
2853 64782 msflag=sSECRET01+(scr->sflag[i]-mfSECRETS01);
2854
4/4
✓ Branch 0 taken 47230 times.
✓ Branch 1 taken 2970891 times.
✓ Branch 2 taken 46999 times.
✓ Branch 3 taken 231 times.
3018121 else if(combobuf[scr->data[i]].flag>=mfSECRETS01 && combobuf[scr->data[i]].flag<=mfSECRETS16)
2855 231 msflag=sSECRET01+(combobuf[scr->data[i]].flag-mfSECRETS01);
2856 else
2857 3017890 msflag=0;
2858
2859
4/4
✓ Branch 0 taken 915800 times.
✓ Branch 1 taken 2167103 times.
✓ Branch 2 taken 72 times.
✓ Branch 3 taken 915728 times.
3082903 if(!high16only || single>=0)
2860 {
2861 2167175 int32_t newflag = -1;
2862
2863
2/2
✓ Branch 0 taken 4334350 times.
✓ Branch 1 taken 2167175 times.
6501525 for(int32_t iter=0; iter<2; ++iter)
2864 {
2865 4334350 int32_t checkflag=combobuf[scr->data[i]].flag; //Inherent
2866
2867
2/2
✓ Branch 0 taken 2167175 times.
✓ Branch 1 taken 2167175 times.
4334350 if(iter==1) checkflag=scr->sflag[i]; //Placed
2868
2869 4334350 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
2870
2/2
✓ Branch 0 taken 4322160 times.
✓ Branch 1 taken 12190 times.
4334350 if (ft != -1) //Change the combos for the secret
2871 {
2872 // Use misc. secret flag instead if one is present
2873
2/2
✓ Branch 0 taken 12158 times.
✓ Branch 1 taken 32 times.
12190 if(msflag!=0)
2874 32 ft=msflag;
2875
2876 12190 rpos_handle_t rpos_handle;
2877
2/2
✓ Branch 0 taken 6367 times.
✓ Branch 1 taken 5823 times.
12190 if (from_active_screen)
2878 {
2879 5823 rpos_handle = get_rpos_handle_for_scr(scr, 0, i);
2880 5823 screen_combo_modify_preroutine(rpos_handle);
2881 5823 }
2882
2883
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12190 times.
12190 if(ft==sSECNEXT)
2884 {
2885 scr->data[i]++;
2886 }
2887 else
2888 {
2889 12190 scr->data[i] = scr->secretcombo[ft];
2890 12190 scr->cset[i] = scr->secretcset[ft];
2891 }
2892 12190 newflag = scr->secretflag[ft];
2893
2894
2/2
✓ Branch 0 taken 6367 times.
✓ Branch 1 taken 5823 times.
12190 if (from_active_screen)
2895 5823 screen_combo_modify_postroutine(rpos_handle);
2896 12190 }
2897 4334350 }
2898
2899
2/2
✓ Branch 0 taken 2154991 times.
✓ Branch 1 taken 12184 times.
2167175 if(newflag >-1) scr->sflag[i] = newflag; //Tiered secret
2900
2901
2/2
✓ Branch 0 taken 13003050 times.
✓ Branch 1 taken 2167175 times.
15170225 for(int32_t j=1; j<=6; j++) //Layers
2902 {
2903 13003050 mapscr* layer_scr = screen_handles[j].scr;
2904
2/2
✓ Branch 0 taken 3182453 times.
✓ Branch 1 taken 9820597 times.
13003050 if (!layer_scr) continue;
2905
2906
3/4
✓ Branch 0 taken 725 times.
✓ Branch 1 taken 3181728 times.
✓ Branch 2 taken 725 times.
✗ Branch 3 not taken.
3182453 if(single>=0 && i!=single) continue; //If it's got a singular flag and i isn't where the flag is
2907
2908 3182453 int32_t newflag2 = -1;
2909
2910 // Remember the misc. secret flag; if triggered, use this instead
2911
4/4
✓ Branch 0 taken 14180 times.
✓ Branch 1 taken 3168273 times.
✓ Branch 2 taken 4773 times.
✓ Branch 3 taken 9407 times.
3182453 if(layer_scr->sflag[i]>=mfSECRETS01 && layer_scr->sflag[i]<=mfSECRETS16)
2912 9407 msflag=sSECRET01+(layer_scr->sflag[i]-mfSECRETS01);
2913
4/4
✓ Branch 0 taken 126931 times.
✓ Branch 1 taken 3046115 times.
✓ Branch 2 taken 126560 times.
✓ Branch 3 taken 371 times.
3173046 else if(combobuf[layer_scr->data[i]].flag>=mfSECRETS01 && combobuf[layer_scr->data[i]].flag<=mfSECRETS16)
2914 371 msflag=sSECRET01+(combobuf[layer_scr->data[i]].flag-mfSECRETS01);
2915 else
2916 3172675 msflag=0;
2917
2918
2/2
✓ Branch 0 taken 6364906 times.
✓ Branch 1 taken 3182453 times.
9547359 for(int32_t iter=0; iter<2; ++iter)
2919 {
2920 6364906 int32_t checkflag=combobuf[layer_scr->data[i]].flag; //Inherent
2921
2/2
✓ Branch 0 taken 3182453 times.
✓ Branch 1 taken 3182453 times.
6364906 if(iter==1) checkflag=layer_scr->sflag[i]; //Placed
2922
2923 6364906 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
2924
2/2
✓ Branch 0 taken 6364428 times.
✓ Branch 1 taken 478 times.
6364906 if (ft != -1) //Change the combos for the secret
2925 {
2926 // Use misc. secret flag instead if one is present
2927
2/2
✓ Branch 0 taken 476 times.
✓ Branch 1 taken 2 times.
478 if(msflag!=0)
2928 2 ft=msflag;
2929
2930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 478 times.
478 if(ft==sSECNEXT)
2931 {
2932 layer_scr->data[i]++;
2933 }
2934 else
2935 {
2936 478 layer_scr->data[i] = layer_scr->secretcombo[ft];
2937 478 layer_scr->cset[i] = layer_scr->secretcset[ft];
2938 }
2939 478 newflag2 = layer_scr->secretflag[ft];
2940 478 int32_t c=layer_scr->data[i];
2941 478 int32_t cs=layer_scr->cset[i];
2942
2943
3/4
✓ Branch 0 taken 406 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 406 times.
✗ Branch 3 not taken.
478 if (from_active_screen && combobuf[c].type==cSPINTILE1) //Surely this means we can have spin tiles on layers 3+? Isn't that bad? ~Joe123
2944 {
2945 auto [offx, offy] = translate_screen_coordinates_to_world(screen, COMBOX(i), COMBOY(i));
2946 addenemy(screen,offx,offy,(cs<<12)+eSPINTILE1,combobuf[c].o_tile+zc_max(1,combobuf[c].frames));
2947 }
2948 478 }
2949 6364906 }
2950
2951
2/2
✓ Branch 0 taken 478 times.
✓ Branch 1 taken 3181975 times.
3182453 if(newflag2 >-1) layer_scr->sflag[i] = newflag2; //Tiered secret
2952 3182453 }
2953 2167175 }
2954 3082903 }
2955
2956 17953 word c = scr->numFFC();
2957
2/2
✓ Branch 0 taken 505431 times.
✓ Branch 1 taken 17953 times.
523384 for(word i=0; i<c; i++) //FFC 'trigger flags'
2958 {
2959
3/4
✓ Branch 0 taken 491511 times.
✓ Branch 1 taken 13920 times.
✓ Branch 2 taken 13920 times.
✗ Branch 3 not taken.
505431 if(single>=0) if(i+176!=single) continue;
2960
2961
3/4
✓ Branch 0 taken 165613 times.
✓ Branch 1 taken 325898 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 165613 times.
491511 if((!high16only)||(single>=0))
2962 {
2963 //for (int32_t iter=0; iter<1; ++iter) // Only one kind of FFC flag now.
2964 {
2965 325898 int32_t checkflag=combobuf[scr->ffcs[i].data].flag; //Inherent
2966 //No placed flags yet
2967
2968 325898 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
2969
2/2
✓ Branch 0 taken 325867 times.
✓ Branch 1 taken 31 times.
325898 if (ft != -1) //Change the ffc's combo
2970 {
2971
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31 times.
31 if(ft==sSECNEXT)
2972 {
2973 zc_ffc_modify(scr->ffcs[i], 1);
2974 }
2975 else
2976 {
2977 31 zc_ffc_set(scr->ffcs[i], scr->secretcombo[ft]);
2978 31 scr->ffcs[i].cset = scr->secretcset[ft];
2979 }
2980 31 }
2981 }
2982 325898 }
2983 491511 }
2984
2985
2/2
✓ Branch 0 taken 15571 times.
✓ Branch 1 taken 2382 times.
17953 if(checktrigger) //Hit all triggers->16-31
2986 {
2987 2382 checktrigger=false;
2988
2989
2/2
✓ Branch 0 taken 2373 times.
✓ Branch 1 taken 9 times.
2382 if(scr->flags6&fTRIGGERF1631)
2990 {
2991 9 int32_t tr = findtrigger(screen); //Normal flags
2992
2993
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
9 if(tr)
2994 {
2995 5 Z_eventlog("Hit All Triggers->16-31 not fulfilled (%d trigger flag%s remain).\n", tr, tr>1?"s":"");
2996 5 goto endhe;
2997 }
2998 4 }
2999 2377 }
3000
3001
2/2
✓ Branch 0 taken 3158848 times.
✓ Branch 1 taken 17948 times.
3176796 for(int32_t i=0; i<176; i++) // Do the 16-31 secrets
3002 {
3003 //If it's an enemies->secret screen, only do the high 16 if told to
3004 //That way you can have secret and burn/bomb entrance separately
3005 3158848 bool old_enem_secret = get_qr(qr_ENEMIES_SECRET_ONLY_16_31);
3006
6/6
✓ Branch 0 taken 2772528 times.
✓ Branch 1 taken 386320 times.
✓ Branch 2 taken 85184 times.
✓ Branch 3 taken 3073664 times.
✓ Branch 4 taken 19536 times.
✓ Branch 5 taken 65648 times.
3158848 if(((!(old_enem_secret && (scr->flags2&fCLEARSECRET)) /*Enemies->Secret*/ && single < 0) || high16only || scr->flags4&fENEMYSCRTPERM))
3007 {
3008 3093200 int32_t newflag = -1;
3009
3010
2/2
✓ Branch 0 taken 6186400 times.
✓ Branch 1 taken 3093200 times.
9279600 for(int32_t iter=0; iter<2; ++iter)
3011 {
3012 6186400 int32_t checkflag=combobuf[scr->data[i]].flag; //Inherent
3013
3014
2/2
✓ Branch 0 taken 3093200 times.
✓ Branch 1 taken 3093200 times.
6186400 if(iter==1) checkflag=scr->sflag[i]; //Placed
3015
3016
4/4
✓ Branch 0 taken 160831 times.
✓ Branch 1 taken 6025569 times.
✓ Branch 2 taken 94766 times.
✓ Branch 3 taken 66065 times.
6186400 if((checkflag > 15)&&(checkflag < 32)) //If we've got a 16->32 flag change the combo
3017 {
3018 66065 rpos_handle_t rpos_handle;
3019
2/2
✓ Branch 0 taken 9951 times.
✓ Branch 1 taken 56114 times.
66065 if (from_active_screen)
3020 {
3021 56114 rpos_handle = get_rpos_handle_for_scr(scr, 0, i);
3022 56114 screen_combo_modify_preroutine(rpos_handle);
3023 56114 }
3024
3025 66065 scr->data[i] = scr->secretcombo[checkflag-16+4];
3026 66065 scr->cset[i] = scr->secretcset[checkflag-16+4];
3027 66065 newflag = scr->secretflag[checkflag-16+4];
3028
3029
2/2
✓ Branch 0 taken 9951 times.
✓ Branch 1 taken 56114 times.
66065 if (from_active_screen)
3030 56114 screen_combo_modify_postroutine(rpos_handle);
3031 66065 }
3032 6186400 }
3033
3034
2/2
✓ Branch 0 taken 3027159 times.
✓ Branch 1 taken 66041 times.
3093200 if(newflag >-1) scr->sflag[i] = newflag; //Tiered flag
3035
3036
2/2
✓ Branch 0 taken 18559200 times.
✓ Branch 1 taken 3093200 times.
21652400 for(int32_t j=1; j<=6; j++) //Layers
3037 {
3038 18559200 mapscr* layer_scr = screen_handles[j].scr;
3039
2/2
✓ Branch 0 taken 4859888 times.
✓ Branch 1 taken 13699312 times.
18559200 if (!layer_scr) continue;
3040
3041 4859888 int32_t newflag2 = -1;
3042
3043
2/2
✓ Branch 0 taken 9719776 times.
✓ Branch 1 taken 4859888 times.
14579664 for(int32_t iter=0; iter<2; ++iter)
3044 {
3045 9719776 int32_t checkflag=combobuf[layer_scr->data[i]].flag; //Inherent
3046
3047
2/2
✓ Branch 0 taken 4859888 times.
✓ Branch 1 taken 4859888 times.
9719776 if(iter==1) checkflag=layer_scr->sflag[i]; //Placed
3048
3049
4/4
✓ Branch 0 taken 151244 times.
✓ Branch 1 taken 9568532 times.
✓ Branch 2 taken 131622 times.
✓ Branch 3 taken 19622 times.
9719776 if((checkflag > 15)&&(checkflag < 32)) //If we've got a 16->32 flag change the combo
3050 {
3051 19622 layer_scr->data[i] = layer_scr->secretcombo[checkflag-16+4];
3052 19622 layer_scr->cset[i] = layer_scr->secretcset[checkflag-16+4];
3053 19622 newflag2 = layer_scr->secretflag[checkflag-16+4];
3054 19622 }
3055 9719776 }
3056
3057
2/2
✓ Branch 0 taken 4840266 times.
✓ Branch 1 taken 19622 times.
4859888 if(newflag2 >-1) layer_scr->sflag[i] = newflag2; //Tiered flag
3058 4859888 }
3059 3093200 }
3060 3158848 }
3061
3062
2/2
✓ Branch 0 taken 505271 times.
✓ Branch 1 taken 17948 times.
523219 for(word i=0; i<c; i++) // FFCs
3063 {
3064
6/6
✓ Branch 0 taken 465668 times.
✓ Branch 1 taken 39603 times.
✓ Branch 2 taken 15367 times.
✓ Branch 3 taken 489904 times.
✓ Branch 4 taken 3530 times.
✓ Branch 5 taken 11837 times.
505271 if((!(scr->flags2&fCLEARSECRET) /*Enemies->Secret*/ && single < 0) || high16only || scr->flags4&fENEMYSCRTPERM)
3065 {
3066 493434 int32_t checkflag=combobuf[scr->ffcs[i].data].flag; //Inherent
3067
3068 //No placed flags yet
3069
4/4
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 493366 times.
✓ Branch 2 taken 56 times.
✓ Branch 3 taken 12 times.
493434 if((checkflag > 15)&&(checkflag < 32)) //If we find a flag, change the combo
3070 {
3071
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 3 times.
12 if (from_active_screen)
3072 9 zc_ffc_set(scr->ffcs[i], scr->secretcombo[checkflag - 16 + 4]);
3073 else
3074 3 scr->ffcs[i].data = scr->secretcombo[checkflag - 16 + 4];
3075 12 scr->ffcs[i].cset = scr->secretcset[checkflag-16+4];
3076 12 }
3077 493434 }
3078 523219 }
3079
3080 endhe:
3081
3082
1/2
✓ Branch 0 taken 17953 times.
✗ Branch 1 not taken.
17953 if (scr->flags4&fDISABLETIME) //Finish timed warp if 'Secrets Disable Timed Warp'
3083 {
3084 if (from_active_screen)
3085 activated_timed_warp = true;
3086 scr->timedwarptics = 0;
3087 }
3088 17953 }
3089
3090 // x,y are world coordinates.
3091 // Returns true if there is a flag (either combo, screen, or ffc) at (x, y).
3092 // Out parameters will be set if the flag is Trigger->Self, which modifies how secrets will be triggered.
3093 13416700 static bool has_flag_trigger(int32_t x, int32_t y, int32_t flag, rpos_t& out_rpos, bool& out_single16)
3094 {
3095
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13416700 times.
13416700 if (!is_in_world_bounds(x, y)) return false;
3096
3097 13416700 bool found_cflag = false;
3098 13416700 bool found_nflag = false;
3099 13416700 bool single16 = false;
3100 13416700 rpos_t rpos = rpos_t::None;
3101
3102
2/2
✓ Branch 0 taken 13414631 times.
✓ Branch 1 taken 93904798 times.
107319429 for (int32_t layer = -1; layer < 6; layer++)
3103 {
3104
2/2
✓ Branch 0 taken 93902729 times.
✓ Branch 1 taken 2069 times.
93904798 if (MAPFLAG2(layer, x, y) == flag)
3105 {
3106 2069 found_nflag = true;
3107 2069 break;
3108 }
3109 93902729 }
3110
3111
2/2
✓ Branch 0 taken 13416396 times.
✓ Branch 1 taken 93915624 times.
107332020 for (int32_t layer = -1; layer < 6; layer++)
3112 {
3113
2/2
✓ Branch 0 taken 93915320 times.
✓ Branch 1 taken 304 times.
93915624 if (MAPCOMBOFLAG2(layer, x, y) == flag)
3114 {
3115 304 found_cflag = true;
3116 304 break;
3117 }
3118 93915320 }
3119
3120
2/2
✓ Branch 0 taken 93916900 times.
✓ Branch 1 taken 13416700 times.
107333600 for (int32_t i=-1; i<6; i++) // Look for Trigger->Self on all layers
3121 {
3122
2/2
✓ Branch 0 taken 93902417 times.
✓ Branch 1 taken 14483 times.
93916900 if (found_nflag) // Trigger->Self (a.k.a Singular) is inherent
3123 {
3124
3/4
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 14371 times.
✓ Branch 2 taken 112 times.
✗ Branch 3 not taken.
14483 if ((MAPCOMBOFLAG2(i, x, y) == mfSINGLE) && (MAPFLAG2(i, x, y) == flag))
3125 {
3126 112 rpos = COMBOPOS_REGION(x, y);
3127 112 }
3128
3/4
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 14319 times.
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
14371 else if ((MAPCOMBOFLAG2(i, x, y) == mfSINGLE16) && (MAPFLAG2(i, x, y) == flag))
3129 {
3130 52 rpos = COMBOPOS_REGION(x, y);
3131 52 single16 = true;
3132 52 }
3133 14483 }
3134
3135
2/2
✓ Branch 0 taken 93914772 times.
✓ Branch 1 taken 2128 times.
93916900 if (found_cflag) // Trigger->Self (a.k.a Singular) is non-inherent
3136 {
3137
3/4
✓ Branch 0 taken 255 times.
✓ Branch 1 taken 1873 times.
✓ Branch 2 taken 255 times.
✗ Branch 3 not taken.
2128 if ((MAPFLAG2(i, x, y) == mfSINGLE) && (MAPCOMBOFLAG2(i, x, y) == flag))
3138 {
3139 255 rpos = COMBOPOS_REGION(x, y);
3140 255 }
3141
3/4
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1853 times.
✓ Branch 2 taken 20 times.
✗ Branch 3 not taken.
1873 else if ((MAPFLAG2(i, x, y) == mfSINGLE16) && (MAPCOMBOFLAG2(i, x, y) == flag))
3142 {
3143 20 rpos = COMBOPOS_REGION(x, y);
3144 20 single16 = true;
3145 20 }
3146 2128 }
3147 93916900 }
3148
3149 13416700 out_rpos = rpos;
3150 13416700 out_single16 = single16;
3151
4/4
✓ Branch 0 taken 13414631 times.
✓ Branch 1 taken 2069 times.
✓ Branch 2 taken 13414329 times.
✓ Branch 3 taken 302 times.
13416700 return found_nflag || found_cflag || MAPFFCOMBOFLAG(x,y) == flag;
3152 13416700 }
3153
3154 4426399 bool trigger_secrets_if_flag(int32_t x, int32_t y, int32_t flag, bool setflag)
3155 {
3156
8/8
✓ Branch 0 taken 4426159 times.
✓ Branch 1 taken 240 times.
✓ Branch 2 taken 4424262 times.
✓ Branch 3 taken 1897 times.
✓ Branch 4 taken 4423742 times.
✓ Branch 5 taken 520 times.
✓ Branch 6 taken 952 times.
✓ Branch 7 taken 4422790 times.
4426399 if (x < -16 || y < -16 || x >= world_w || y >= world_h) return false;
3157
3158 4422790 mapscr* scr = NULL;
3159 4422790 int32_t screen = -1;
3160 4422790 rpos_t trigger_rpos = rpos_t::None;
3161 4422790 bool single16 = false;
3162
3163 4422790 std::vector<std::pair<int, int>> coords;
3164
1/2
✓ Branch 0 taken 4422790 times.
✗ Branch 1 not taken.
4422790 coords.push_back({x, y});
3165
1/2
✓ Branch 0 taken 4422790 times.
✗ Branch 1 not taken.
4422790 coords.push_back({x + 15, y});
3166
1/2
✓ Branch 0 taken 4422790 times.
✗ Branch 1 not taken.
4422790 coords.push_back({x, y + 15});
3167
1/2
✓ Branch 0 taken 4422790 times.
✗ Branch 1 not taken.
4422790 coords.push_back({x + 15, y + 15});
3168 4422790 std::vector<rpos_t> rposes_seen;
3169
2/2
✓ Branch 0 taken 4420408 times.
✓ Branch 1 taken 17685900 times.
83891646 for (auto [x, y] : coords)
3170 {
3171
2/4
✓ Branch 0 taken 17685900 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17685900 times.
✗ Branch 3 not taken.
35371800 rpos_t rpos = COMBOPOS_REGION_B(x, y);
3172
2/2
✓ Branch 0 taken 17473587 times.
✓ Branch 1 taken 212313 times.
17685900 if (rpos == rpos_t::None)
3173 212313 continue;
3174
3175
4/6
✓ Branch 0 taken 17473587 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17473587 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 17473576 times.
34947174 if (MAPFFCOMBOFLAG(x, y) == flag)
3176 {
3177
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
22 screen = get_screen_for_world_xy(x, y);
3178 11 break;
3179 }
3180
3181 17473576 bool seen = false;
3182
2/2
✓ Branch 0 taken 13416700 times.
✓ Branch 1 taken 21973930 times.
35390630 for (rpos_t r : rposes_seen)
3183 {
3184
2/2
✓ Branch 0 taken 17917054 times.
✓ Branch 1 taken 4056876 times.
21973930 if (r == rpos)
3185 {
3186 4056876 seen = true;
3187 4056876 break;
3188 }
3189 }
3190
2/2
✓ Branch 0 taken 13416700 times.
✓ Branch 1 taken 4056876 times.
17473576 if (seen)
3191 4056876 continue;
3192
3193
1/2
✓ Branch 0 taken 13416700 times.
✗ Branch 1 not taken.
13416700 rposes_seen.push_back(rpos);
3194
4/6
✓ Branch 0 taken 13416700 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13416700 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2371 times.
✓ Branch 5 taken 13414329 times.
26833400 if (has_flag_trigger(x, y, flag, trigger_rpos, single16))
3195 {
3196
2/4
✓ Branch 0 taken 2371 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2371 times.
✗ Branch 3 not taken.
4742 screen = get_screen_for_world_xy(x, y);
3197 2371 break;
3198 }
3199 }
3200
3201
3/4
✓ Branch 0 taken 2382 times.
✓ Branch 1 taken 4420408 times.
✓ Branch 2 taken 2382 times.
✗ Branch 3 not taken.
4422790 if (screen != -1) scr = get_scr(screen);
3202
2/2
✓ Branch 0 taken 2382 times.
✓ Branch 1 taken 4420408 times.
4422790 if (!scr) return false;
3203
3204
2/2
✓ Branch 0 taken 1943 times.
✓ Branch 1 taken 439 times.
2382 if (trigger_rpos == rpos_t::None)
3205 {
3206 1943 checktrigger = true;
3207
1/2
✓ Branch 0 taken 1943 times.
✗ Branch 1 not taken.
1943 trigger_secrets_for_screen(TriggerSource::Unspecified, screen);
3208 1943 }
3209 else
3210 {
3211 439 checktrigger = true;
3212
2/4
✓ Branch 0 taken 439 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 439 times.
✗ Branch 3 not taken.
439 trigger_secrets_for_screen(TriggerSource::Singular, scr, single16, RPOS_TO_POS(trigger_rpos));
3213 }
3214
3215
1/2
✓ Branch 0 taken 2382 times.
✗ Branch 1 not taken.
2382 sfx(scr->secretsfx);
3216
3217
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 2376 times.
2382 if(scr->flags6&fTRIGGERFPERM)
3218 {
3219
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 int32_t flags_remaining = findtrigger(screen); //Normal flags
3220
3221
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (flags_remaining)
3222 {
3223
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 Z_eventlog("Hit All Triggers->Perm Secret not fulfilled (%d trigger flag%s remain).\n", flags_remaining, flags_remaining>1?"s":"");
3224 3 setflag=false;
3225 3 }
3226
3227 // Only actually trigger secrets now if 1) all triggers are gone and 2) QR qr_ALLTRIG_PERMSEC_NO_TEMP is off, in
3228 // which case only the screen state for mSECRET may be set below.
3229
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
6 if (!flags_remaining && !get_qr(qr_ALLTRIG_PERMSEC_NO_TEMP))
3230 {
3231 trigger_secrets_for_screen(TriggerSource::Unspecified, scr, scr->flags6&fTRIGGERF1631, -1);
3232 }
3233 6 }
3234
3235
5/6
✓ Branch 0 taken 2277 times.
✓ Branch 1 taken 105 times.
✓ Branch 2 taken 2277 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1093 times.
✓ Branch 5 taken 1184 times.
2382 if (setflag && canPermSecret(cur_dmap, screen))
3236
2/2
✓ Branch 0 taken 721 times.
✓ Branch 1 taken 463 times.
1905 if(!(scr->flags5&fTEMPSECRETS))
3237
1/2
✓ Branch 0 taken 721 times.
✗ Branch 1 not taken.
721 setmapflag(scr, mSECRET);
3238
3239 2382 return true;
3240 4426399 }
3241
3242 14527348 void update_slopes()
3243 {
3244
2/2
✓ Branch 0 taken 142356 times.
✓ Branch 1 taken 14527348 times.
14669704 for (auto& p : slopes)
3245 {
3246 142356 slope_object& s = p.second;
3247 142356 s.updateslope(); //sets old x/y poses
3248 }
3249 14527348 }
3250
3251 14121767 void update_freeform_combos()
3252 {
3253 14121767 ffscript_engine(false);
3254
2/2
✓ Branch 0 taken 24172 times.
✓ Branch 1 taken 14097595 times.
14121767 if ( !FFCore.system_suspend[susptUPDATEFFC] )
3255 {
3256 14097595 int wrap_right = world_w + 32;
3257 14097595 int wrap_bottom = world_h + 32;
3258
3259 476620109 for_every_ffc([&](const ffc_handle_t& ffc_handle) {
3260 462522514 mapscr* scr = ffc_handle.scr;
3261 462522514 ffcdata& thisffc = *ffc_handle.ffc;
3262
3263 // Combo 0?
3264
2/2
✓ Branch 0 taken 44992137 times.
✓ Branch 1 taken 417530377 times.
462522514 if(thisffc.data==0)
3265 417530377 return;
3266
3267 // Changer?
3268
2/2
✓ Branch 0 taken 543029 times.
✓ Branch 1 taken 44449108 times.
44992137 if(thisffc.flags&ffc_changer)
3269 543029 return;
3270
3271 // Stationary?
3272
2/2
✓ Branch 0 taken 9844 times.
✓ Branch 1 taken 44439264 times.
44449108 if(thisffc.flags&ffc_stationary)
3273 9844 return;
3274
3275 // Frozen because Hero's holding up an item?
3276
3/4
✓ Branch 0 taken 138282 times.
✓ Branch 1 taken 44300982 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 138282 times.
44439264 if(Hero.getHoldClk()>0 && (thisffc.flags&ffc_ignoreholdup)==0)
3277 138282 return;
3278
3279 // Check for changers
3280
2/2
✓ Branch 0 taken 29543718 times.
✓ Branch 1 taken 14757264 times.
44300982 if (thisffc.link==0)
3281 {
3282 442453057 for_some_ffcs([&](const ffc_handle_t& other_ffc_handle) {
3283
2/2
✓ Branch 0 taken 14755728 times.
✓ Branch 1 taken 412940065 times.
427695793 if (ffc_handle.id == other_ffc_handle.id)
3284 14755728 return true;
3285
3286 412940065 ffcdata& otherffc = *other_ffc_handle.ffc;
3287 // Combo 0?
3288
2/2
✓ Branch 0 taken 144689563 times.
✓ Branch 1 taken 268250502 times.
412940065 if(otherffc.data==0)
3289 268250502 return true;
3290
3291 // Not a changer?
3292
2/2
✓ Branch 0 taken 140701386 times.
✓ Branch 1 taken 3988177 times.
144689563 if(!(otherffc.flags&ffc_changer))
3293 140701386 return true;
3294
3295 // Ignore this changer?
3296
4/4
✓ Branch 0 taken 546579 times.
✓ Branch 1 taken 3441598 times.
✓ Branch 2 taken 299257 times.
✓ Branch 3 taken 3142341 times.
3988177 if((otherffc.x.getInt()==thisffc.changer_x&&otherffc.y.getInt()==thisffc.changer_y) || thisffc.flags&ffc_ignorechanger)
3297 845836 return true;
3298
3299
3/4
✓ Branch 0 taken 2721043 times.
✓ Branch 1 taken 421298 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3562 times.
3145903 if((isonline(thisffc.x.getZLong(), thisffc.y.getZLong(), thisffc.prev_changer_x, thisffc.prev_changer_y, otherffc.x.getZLong(), otherffc.y.getZLong()) || // Along the line, or...
3300 ( // At exactly the same position,
3301
2/2
✓ Branch 0 taken 208792 times.
✓ Branch 1 taken 2512251 times.
2721043 (thisffc.x==otherffc.x && thisffc.y==otherffc.y))
3302
2/2
✓ Branch 0 taken 2303459 times.
✓ Branch 1 taken 2512251 times.
208792 ||
3303 //or imprecision and close enough
3304
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
5024502 ( (thisffc.flags&ffc_imprecisionchanger) && ((abs(thisffc.x.getZLong() - otherffc.x.getZLong()) < 10000) && abs(thisffc.y.getZLong() - otherffc.y.getZLong()) < 10000) )
3305 )
3306 && //and...
3307
2/2
✓ Branch 0 taken 3562 times.
✓ Branch 1 taken 2721195 times.
2724757 (thisffc.prev_changer_x>-10000000 && thisffc.prev_changer_y>-10000000)) // This isn't the first frame on this screen
3308 {
3309 3562 zc_ffc_changer(thisffc, otherffc, ffc_handle.id, other_ffc_handle.id);
3310 3562 return false;
3311 }
3312
3313 2721195 return true;
3314 426679695 });
3315 14757264 }
3316
3317
2/2
✓ Branch 0 taken 29543718 times.
✓ Branch 1 taken 14757264 times.
44300982 ffcdata* linked_ffc = thisffc.link ? get_ffc_handle(thisffc.link - 1).ffc : nullptr;
3318
4/4
✓ Branch 0 taken 14757264 times.
✓ Branch 1 taken 29543718 times.
✓ Branch 2 taken 14679974 times.
✓ Branch 3 taken 14863744 times.
44300982 if (linked_ffc ? !linked_ffc->delay : !thisffc.delay)
3319 {
3320
4/4
✓ Branch 0 taken 182609 times.
✓ Branch 1 taken 14681135 times.
✓ Branch 2 taken 85331 times.
✓ Branch 3 taken 97278 times.
14863744 if(thisffc.link && (thisffc.link-1) != ffc_handle.id)
3321 {
3322 97278 thisffc.prev_changer_x = thisffc.x.getZLong();
3323 97278 thisffc.prev_changer_y = thisffc.y.getZLong();
3324 97278 thisffc.x += linked_ffc->vx;
3325 97278 thisffc.y += linked_ffc->vy;
3326 97278 }
3327 else
3328 {
3329 14766466 thisffc.prev_changer_x = thisffc.x.getZLong();
3330 14766466 thisffc.prev_changer_y = thisffc.y.getZLong();
3331 14766466 thisffc.x += thisffc.vx;
3332 14766466 thisffc.y += thisffc.vy;
3333 14766466 thisffc.vx += thisffc.ax;
3334 14766466 thisffc.vy += thisffc.ay;
3335
3336
3337
2/2
✓ Branch 0 taken 444012 times.
✓ Branch 1 taken 14322454 times.
14766466 if(get_qr(qr_OLD_FFC_SPEED_CAP))
3338 {
3339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14322454 times.
14322454 if(thisffc.vx>128) thisffc.vx=128;
3340
3341
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14322454 times.
14322454 if(thisffc.vx<-128) thisffc.vx=-128;
3342
3343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14322454 times.
14322454 if(thisffc.vy>128) thisffc.vy=128;
3344
3345
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14322454 times.
14322454 if(thisffc.vy<-128) thisffc.vy=-128;
3346 14322454 }
3347 }
3348 14863744 }
3349 else
3350 {
3351
3/4
✓ Branch 0 taken 1161 times.
✓ Branch 1 taken 76129 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1161 times.
29437238 if(!thisffc.link || (thisffc.link-1) == ffc_handle.id)
3352 76129 thisffc.delay--;
3353 }
3354
3355 // Check if the FFC's off the side of the screen
3356
3357 // Left
3358
2/2
✓ Branch 0 taken 10449 times.
✓ Branch 1 taken 14930585 times.
14941034 if(thisffc.x<-32)
3359 {
3360
2/2
✓ Branch 0 taken 253 times.
✓ Branch 1 taken 10196 times.
10449 if(scr->flags6&fWRAPAROUNDFF)
3361 {
3362 253 thisffc.x = wrap_right+(thisffc.x+32);
3363 253 thisffc.solid_update(false);
3364 253 thisffc.prev_changer_y = thisffc.y.getZLong();
3365 // Re-enable previous changer
3366 253 thisffc.changer_x = -1000;
3367 253 thisffc.changer_y = -1000;
3368 253 }
3369
2/2
✓ Branch 0 taken 10127 times.
✓ Branch 1 taken 69 times.
10196 else if(thisffc.x<-64)
3370 {
3371 69 zc_ffc_set(thisffc, 0);
3372 69 thisffc.flags&=~ffc_carryover;
3373 69 }
3374 10449 }
3375 // Right
3376
2/2
✓ Branch 0 taken 14930404 times.
✓ Branch 1 taken 181 times.
14930585 else if(thisffc.x>=wrap_right)
3377 {
3378
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 53 times.
181 if(scr->flags6&fWRAPAROUNDFF)
3379 {
3380 128 thisffc.x = thisffc.x-wrap_right-32;
3381 128 thisffc.solid_update(false);
3382 128 thisffc.prev_changer_y = thisffc.y.getZLong();
3383 128 thisffc.changer_x = -1000;
3384 128 thisffc.changer_y = -1000;
3385 128 }
3386 else
3387 {
3388 53 zc_ffc_set(thisffc, 0);
3389 53 thisffc.flags&=~ffc_carryover;
3390 }
3391 181 }
3392
3393 // Top
3394
2/2
✓ Branch 0 taken 25480 times.
✓ Branch 1 taken 14915554 times.
14941034 if(thisffc.y<-32)
3395 {
3396
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 25472 times.
25480 if(scr->flags6&fWRAPAROUNDFF)
3397 {
3398 8 thisffc.y = wrap_bottom+(thisffc.y+32);
3399 8 thisffc.solid_update(false);
3400 8 thisffc.prev_changer_x = thisffc.x.getZLong();
3401 8 thisffc.changer_x = -1000;
3402 8 thisffc.changer_y = -1000;
3403 8 }
3404
2/2
✓ Branch 0 taken 25155 times.
✓ Branch 1 taken 317 times.
25472 else if(thisffc.y<-64)
3405 {
3406 317 zc_ffc_set(thisffc, 0);
3407 317 thisffc.flags&=~ffc_carryover;
3408 317 }
3409 25480 }
3410 // Bottom
3411
2/2
✓ Branch 0 taken 14914710 times.
✓ Branch 1 taken 844 times.
14915554 else if(thisffc.y>=wrap_bottom)
3412 {
3413
2/2
✓ Branch 0 taken 753 times.
✓ Branch 1 taken 91 times.
844 if(scr->flags6&fWRAPAROUNDFF)
3414 {
3415 753 thisffc.y = thisffc.y-wrap_bottom-32;
3416 753 thisffc.solid_update(false);
3417 753 thisffc.prev_changer_y = thisffc.x.getZLong();
3418 753 thisffc.changer_x = -1000;
3419 753 thisffc.changer_y = -1000;
3420 753 }
3421 else
3422 {
3423 91 zc_ffc_set(thisffc, 0);
3424 91 thisffc.flags&=~ffc_carryover;
3425 }
3426 844 }
3427 14941034 thisffc.solid_update();
3428 433162566 });
3429 14097595 }
3430 14121767 }
3431
3432 2060275 bool hitcombo(int32_t x, int32_t y, int32_t combotype, byte layers)
3433 {
3434
2/2
✓ Branch 0 taken 14418781 times.
✓ Branch 1 taken 2059751 times.
16478532 for(int q = 0; q < 7; ++q)
3435 {
3436
2/2
✓ Branch 0 taken 12358506 times.
✓ Branch 1 taken 2060275 times.
14418781 if(layers&(1<<q)) //if layer is to be checked
3437
2/2
✓ Branch 0 taken 2059751 times.
✓ Branch 1 taken 524 times.
2060275 if(COMBOTYPE2(q-1,x,y)==combotype) //matching type
3438 524 return true;
3439 14418257 }
3440 2059751 return false;
3441 2060275 }
3442
3443 412055 int gethitcombo(int32_t x, int32_t y, int32_t combotype, byte layers)
3444 {
3445
2/2
✓ Branch 0 taken 2884385 times.
✓ Branch 1 taken 412055 times.
3296440 for(int q = 0; q < 7; ++q)
3446 {
3447
2/2
✓ Branch 0 taken 2472330 times.
✓ Branch 1 taken 412055 times.
2884385 if(layers&(1<<q)) //if layer is to be checked
3448
1/2
✓ Branch 0 taken 412055 times.
✗ Branch 1 not taken.
412055 if(COMBOTYPE2(q-1,x,y)==combotype) //matching type
3449 return MAPCOMBO2(q-1,x,y);
3450 2884385 }
3451 412055 return -1;
3452 412055 }
3453
3454 bool hitflag(int32_t x, int32_t y, int32_t flagtype, byte layers)
3455 {
3456 for(int q = 0; q < 7; ++q)
3457 {
3458 if(layers&(1<<q)) //if layer is to be checked
3459 if(MAPFLAG2(q-1,x,y)==flagtype||MAPCOMBOFLAG2(q-1,x,y)==flagtype) //matching flag
3460 return true;
3461 }
3462 return false;
3463 }
3464
3465 218 optional<int> nextscr(int screen, int dir)
3466 {
3467 218 auto [m, s] = nextscr2(cur_map, screen, dir);
3468
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 218 times.
218 if (m == -1) return nullopt;
3469 436 return (m<<7) + s;
3470 218 }
3471
3472 1058 std::pair<int32_t, int32_t> nextscr2(int32_t dir)
3473 {
3474 1058 int32_t map = cur_map;
3475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1058 times.
1058 int32_t screen = screenscrolling ? scrolling_hero_screen : hero_screen;
3476 1058 return nextscr2(map, screen, dir);
3477 }
3478
3479 5545 std::pair<int32_t, int32_t> nextscr2(int map, int screen, int32_t dir)
3480 {
3481 5545 screen = screen_index_direction(screen, (direction)dir);
3482
3483 // need to check for screens on other maps, 's' not valid, etc.
3484 5545 int32_t index = (hero_scr->sidewarpindex >> (dir*2))&3;
3485
3486 // Fun fact: when a scrolling warp is triggered, this function
3487 // is never even called! - Saf
3488
2/2
✓ Branch 0 taken 3298 times.
✓ Branch 1 taken 2247 times.
6089 if(hero_scr->sidewarptype[index] == 3) // scrolling warp
3489 {
3490
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 481 times.
✓ Branch 2 taken 525 times.
✓ Branch 3 taken 545 times.
✓ Branch 4 taken 696 times.
2247 switch(dir)
3491 {
3492 case up:
3493
2/2
✓ Branch 0 taken 83 times.
✓ Branch 1 taken 398 times.
481 if(!(hero_scr->flags2&wfUP)) goto nowarp;
3494
3495 83 break;
3496
3497 case down:
3498
2/2
✓ Branch 0 taken 79 times.
✓ Branch 1 taken 446 times.
525 if(!(hero_scr->flags2&wfDOWN)) goto nowarp;
3499
3500 79 break;
3501
3502 case left:
3503
2/2
✓ Branch 0 taken 209 times.
✓ Branch 1 taken 336 times.
545 if(!(hero_scr->flags2&wfLEFT)) goto nowarp;
3504
3505 209 break;
3506
3507 case right:
3508
2/2
✓ Branch 0 taken 173 times.
✓ Branch 1 taken 523 times.
696 if(!(hero_scr->flags2&wfRIGHT)) goto nowarp;
3509
3510 173 break;
3511 }
3512
3513 544 map = DMaps[hero_scr->sidewarpdmap[index]].map;
3514 544 screen = hero_scr->sidewarpscr[index] + DMaps[hero_scr->sidewarpdmap[index]].xoff;
3515 544 }
3516
3517 nowarp:
3518
4/4
✓ Branch 0 taken 5481 times.
✓ Branch 1 taken 64 times.
✓ Branch 2 taken 112 times.
✓ Branch 3 taken 5369 times.
5545 if(screen<0||screen>=128)
3519 176 return {-1, -1};
3520
3521 5369 return {map, screen};
3522 5545 }
3523
3524 389 optional<int> nextscr_mi(int mi, int dir)
3525 {
3526 389 int map = mi/MAPSCRSNORMAL;
3527 389 int screen = mi%MAPSCRSNORMAL;
3528 389 auto [m, s] = nextscr2(map, screen, dir);
3529
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 388 times.
389 if (m == -1) return nullopt;
3530 776 return (m<<7) + s;
3531 389 }
3532
3533 2083 void bombdoor(int32_t x,int32_t y)
3534 {
3535
2/2
✓ Branch 0 taken 2063 times.
✓ Branch 1 taken 20 times.
2083 if (!is_in_world_bounds(x, y))
3536 20 return;
3537
3538 2063 auto rpos_handle = get_rpos_handle_for_world_xy(x, y, 0);
3539 2063 mapscr* scr = rpos_handle.scr;
3540 2063 int screen = scr->screen;
3541 2819 auto [x0, y0] = translate_screen_coordinates_to_world(rpos_handle.screen);
3542 #define CHECK_RECT(x,y,rx1,ry1,rx2,ry2) (isinRect(x,y,x0+rx1,y0+ry1,x0+rx2,y0+ry2))
3543
3544
12/12
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 1985 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 68 times.
✓ Branch 4 taken 10 times.
✓ Branch 5 taken 68 times.
✓ Branch 6 taken 10 times.
✓ Branch 7 taken 68 times.
✓ Branch 8 taken 10 times.
✓ Branch 9 taken 68 times.
✓ Branch 10 taken 10 times.
✓ Branch 11 taken 68 times.
2063 if(scr->door[0]==dBOMB && CHECK_RECT(x,y,100,0,139,48))
3545 {
3546 68 scr->door[0]=dBOMBED;
3547 68 putdoor(scr, scrollbuf, 0, dBOMBED);
3548 68 setmapflag(scr, mDOOR_UP);
3549 68 markBmap(-1, screen);
3550
3551
1/2
✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
68 if(auto v = nextscr(screen, up))
3552 {
3553 68 setmapflag_mi(*v, mDOOR_DOWN);
3554 68 markBmap(-1,*v-(get_currdmap()<<7));
3555 68 }
3556 68 }
3557
3558
12/12
✓ Branch 0 taken 43 times.
✓ Branch 1 taken 2020 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 34 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 34 times.
✓ Branch 6 taken 9 times.
✓ Branch 7 taken 34 times.
✓ Branch 8 taken 9 times.
✓ Branch 9 taken 34 times.
✓ Branch 10 taken 9 times.
✓ Branch 11 taken 34 times.
2063 if(scr->door[1]==dBOMB && CHECK_RECT(x,y,100,112,139,176))
3559 {
3560 34 scr->door[1]=dBOMBED;
3561 34 putdoor(scr, scrollbuf, 1, dBOMBED);
3562 34 setmapflag(scr, mDOOR_DOWN);
3563 34 markBmap(-1, rpos_handle.screen);
3564
3565
1/2
✓ Branch 0 taken 34 times.
✗ Branch 1 not taken.
34 if(auto v = nextscr(rpos_handle.screen, down))
3566 {
3567 34 setmapflag_mi(*v, mDOOR_UP);
3568 34 markBmap(-1,*v-(get_currdmap()<<7));
3569 34 }
3570 34 }
3571
3572
12/12
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 1997 times.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 50 times.
✓ Branch 4 taken 16 times.
✓ Branch 5 taken 50 times.
✓ Branch 6 taken 16 times.
✓ Branch 7 taken 50 times.
✓ Branch 8 taken 16 times.
✓ Branch 9 taken 50 times.
✓ Branch 10 taken 16 times.
✓ Branch 11 taken 50 times.
2063 if(scr->door[2]==dBOMB && CHECK_RECT(x,y,0,60,48,98))
3573 {
3574 50 scr->door[2]=dBOMBED;
3575 50 putdoor(scr, scrollbuf, 2, dBOMBED);
3576 50 setmapflag(scr, mDOOR_LEFT);
3577 50 markBmap(-1, rpos_handle.screen);
3578
3579
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 if(auto v = nextscr(rpos_handle.screen, left))
3580 {
3581 50 setmapflag_mi(*v, mDOOR_RIGHT);
3582 50 markBmap(-1,*v-(get_currdmap()<<7));
3583 50 }
3584 50 }
3585
3586
12/12
✓ Branch 0 taken 80 times.
✓ Branch 1 taken 1983 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 66 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 66 times.
✓ Branch 6 taken 14 times.
✓ Branch 7 taken 66 times.
✓ Branch 8 taken 14 times.
✓ Branch 9 taken 66 times.
✓ Branch 10 taken 14 times.
✓ Branch 11 taken 66 times.
2063 if(scr->door[3]==dBOMB && CHECK_RECT(x,y,192,60,240,98))
3587 {
3588 66 scr->door[3]=dBOMBED;
3589 66 putdoor(scr, scrollbuf, 3, dBOMBED);
3590 66 setmapflag(scr, mDOOR_RIGHT);
3591 66 markBmap(-1, rpos_handle.screen);
3592
3593
1/2
✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
66 if(auto v = nextscr(rpos_handle.screen, right))
3594 {
3595 66 setmapflag_mi(*v, mDOOR_LEFT);
3596 66 markBmap(-1,*v-(get_currdmap()<<7));
3597 66 }
3598 66 }
3599 2083 }
3600
3601 6290434885 void draw_cmb(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset,
3602 bool over, bool transp)
3603 {
3604 6290434885 auto& cmb = combobuf[cid];
3605
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6290434885 times.
6290434885 if(cmb.animflags & AF_EDITOR_ONLY)
3606 return;
3607
2/2
✓ Branch 0 taken 3273532307 times.
✓ Branch 1 taken 3016902578 times.
6290434885 if(over)
3608 {
3609
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3273532307 times.
3273532307 if(cmb.animflags & AF_TRANSPARENT)
3610 transp = !transp;
3611
2/2
✓ Branch 0 taken 312966908 times.
✓ Branch 1 taken 2960565399 times.
3273532307 if(transp)
3612 312966908 overcombotranslucent(dest, x, y, cid, cset, 128);
3613 2960565399 else overcombo(dest, x, y, cid, cset);
3614 3273532307 }
3615 3016902578 else putcombo(dest, x, y, cid, cset);
3616 6290434885 }
3617 6290443333 void draw_cmb_pos(BITMAP* dest, int32_t x, int32_t y, rpos_t rpos, int32_t cid,
3618 int32_t cset, byte layer, bool over, bool transp)
3619 {
3620
2/2
✓ Branch 0 taken 742631437 times.
✓ Branch 1 taken 5547811896 times.
6290443333 if (rpos != rpos_t::None)
3621 {
3622 5547811896 rpos_t plrpos = COMBOPOS_REGION_B(Hero.x+8, Hero.y+8);
3623
2/2
✓ Branch 0 taken 726993 times.
✓ Branch 1 taken 5547084903 times.
5547811896 if (plrpos != rpos_t::None)
3624 {
3625 5547084903 bool dosw = false;
3626
4/4
✓ Branch 0 taken 52424 times.
✓ Branch 1 taken 5547032479 times.
✓ Branch 2 taken 43976 times.
✓ Branch 3 taken 8448 times.
5547084903 if (rpos == hooked_comborpos && (hooked_layerbits & (1<<layer)))
3627 {
3628
1/2
✓ Branch 0 taken 8448 times.
✗ Branch 1 not taken.
8448 if(hooked_undercombos[layer] > -1)
3629 {
3630 draw_cmb(dest, x, y,
3631 hooked_undercombos[layer], hooked_undercombos[layer+7], over, transp);
3632 }
3633 8448 dosw = true;
3634 8448 }
3635
4/4
✓ Branch 0 taken 31486879 times.
✓ Branch 1 taken 5515589576 times.
✓ Branch 2 taken 8448 times.
✓ Branch 3 taken 31478431 times.
5547076455 else if (rpos == plrpos && (hooked_layerbits & (1<<(layer+8))))
3636 {
3637 8448 dosw = true;
3638 8448 }
3639
2/2
✓ Branch 0 taken 5547068007 times.
✓ Branch 1 taken 16896 times.
5547084903 if (dosw)
3640 {
3641
1/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 16896 times.
✗ Branch 3 not taken.
16896 switch (Hero.switchhookstyle)
3642 {
3643 default: case swPOOF:
3644 break; //Nothing special here
3645 case swFLICKER:
3646 {
3647
2/2
✓ Branch 0 taken 8448 times.
✓ Branch 1 taken 8448 times.
16896 if(abs(Hero.switchhookclk-33)&0b1000)
3648 8448 break; //Drawn this frame
3649 8448 return; //Not drawn this frame
3650 }
3651 case swRISE:
3652 {
3653 //Draw rising up
3654 y -= 8-(abs(Hero.switchhookclk-32)/4);
3655 break;
3656 }
3657 }
3658 8448 }
3659 5547076455 }
3660 5547803448 }
3661
3662 6290434885 draw_cmb(dest, x, y, cid, cset, over, transp);
3663 6290443333 }
3664
3665 // `draw_cmb_pos` only does meaningful work if the combo being drawn is within the bounds of
3666 // the `bmp` bitmap. However, even getting to the point where `puttile16` (for example) knows
3667 // to cull is somewhat expensive. Since it can only draw 16x16 pixels, we can do the equivalent
3668 // culling here by determining the rows/columns that are within the bitmap bounds. This nets
3669 // on the order of ~30 FPS in uncapped mode on my machine, depending on the viewport/region size.
3670 //
3671 // These two inequalities must be true for `draw_cmb_pos` to do anything useful:
3672 //
3673 // -16 < comboPositionX*16 + x < bitmapWidth
3674 // -16 < comboPositionY*16 + y < bitmapHeight
3675 //
3676 // The following start/end values are derived directly from the above.
3677 //
3678 // `x` and `y` are the offsets the combos will be drawn into the bitmap.
3679 38916322 static void get_bounds_for_draw_cmb_calls(BITMAP* bmp, int x, int y, int& start_x, int& end_x, int& start_y, int& end_y)
3680 {
3681 // if (bmp->clip)
3682 // {
3683 // start_x = MAX(0, ceil((bmp->cl - 15 - x) / 16.0));
3684 // end_x = MIN(16, ceil((bmp->cr - x) / 16.0));
3685 // start_y = MAX(0, ceil((bmp->ct - 15 - y) / 16.0));
3686 // end_y = MIN(11, ceil((bmp->cb - y) / 16.0));
3687 // return;
3688 // }
3689
3690
2/2
✓ Branch 0 taken 2148735 times.
✓ Branch 1 taken 36767587 times.
38916322 start_x = MAX(0, ceil((-15 - x) / 16.0));
3691
2/2
✓ Branch 0 taken 2158572 times.
✓ Branch 1 taken 36757750 times.
38916322 end_x = MIN(16, ceil((bmp->w - x) / 16.0));
3692
2/2
✓ Branch 0 taken 37539871 times.
✓ Branch 1 taken 1376451 times.
38916322 start_y = MAX(0, ceil((-15 - y) / 16.0));
3693
2/2
✓ Branch 0 taken 1661375 times.
✓ Branch 1 taken 37254947 times.
38916322 end_y = MIN(11, ceil((bmp->h - y) / 16.0));
3694 38916322 }
3695
3696 183632964 void do_ffc_layer(BITMAP* bmp, int32_t layer, const screen_handle_t& screen_handle, int32_t x, int32_t y)
3697 {
3698
1/2
✓ Branch 0 taken 183632964 times.
✗ Branch 1 not taken.
183632964 if(!show_ffcs) return;
3699 183632964 mapscr* scr = screen_handle.scr;
3700 183632964 mapscr* base_scr = screen_handle.base_scr;
3701
3702 183632964 y += playing_field_offset;
3703
3704 183632964 bool is_bg_layer = layer < -1;
3705
2/2
✓ Branch 0 taken 33321563 times.
✓ Branch 1 taken 150311401 times.
183632964 int real_layer = is_bg_layer ? abs(layer) : layer;
3706
2/2
✓ Branch 0 taken 183632964 times.
✓ Branch 1 taken 5479560146 times.
5663193110 for(int32_t i = (base_scr->numFFC()-1); i >= 0; --i)
3707 {
3708
2/2
✓ Branch 0 taken 5274062846 times.
✓ Branch 1 taken 205497300 times.
5479560146 if (base_scr->ffcs[i].data == 0)
3709 5274062846 continue;
3710
4/4
✓ Branch 0 taken 37360890 times.
✓ Branch 1 taken 168136410 times.
✓ Branch 2 taken 18682926 times.
✓ Branch 3 taken 18677964 times.
205497300 if(real_layer == 2 && (is_bg_layer != XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG)))
3711 18677964 continue;
3712
4/4
✓ Branch 0 taken 37360890 times.
✓ Branch 1 taken 149458446 times.
✓ Branch 2 taken 18682926 times.
✓ Branch 3 taken 18677964 times.
186819336 else if (real_layer == 3 && (is_bg_layer != XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)))
3713 18677964 continue;
3714
4/4
✓ Branch 0 taken 149463408 times.
✓ Branch 1 taken 18677964 times.
✓ Branch 2 taken 18682926 times.
✓ Branch 3 taken 130780482 times.
168141372 if (real_layer > -1 && base_scr->ffcs[i].layer != real_layer)
3715 130780482 continue;
3716
3717
6/6
✓ Branch 0 taken 3008970 times.
✓ Branch 1 taken 34351920 times.
✓ Branch 2 taken 5110 times.
✓ Branch 3 taken 3003860 times.
✓ Branch 4 taken 2626 times.
✓ Branch 5 taken 2484 times.
37360890 if (screenscrolling && (base_scr->ffcs[i].flags & ffc_carryover) != 0 && screen_handle.screen != scrolling_hero_screen)
3718 2484 continue; //If scrolling, only draw carryover ffcs from newscr and not oldscr.
3719
3720 37358406 base_scr->ffcs[i].draw_ffc(bmp, x, y, (layer==-1));
3721 37358406 }
3722 183632964 }
3723 167626976 void _do_current_ffc_layer(BITMAP* bmp, int32_t layer)
3724 {
3725
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 167626976 times.
167626976 if(!show_ffcs) return;
3726 339832174 for_every_base_screen_in_region([&](mapscr* base_scr, unsigned int region_scr_x, unsigned int region_scr_y) {
3727 172205198 screen_handle_t handle = {base_scr, base_scr, base_scr->screen, 0};
3728 172205198 do_ffc_layer(bmp, layer, handle, 0, 0);
3729 172205198 });
3730 167626976 }
3731 73459770 void do_scrolling_layer(BITMAP *bmp, int32_t type, const screen_handle_t& screen_handle, int32_t x, int32_t y)
3732 {
3733 73459770 mapscr* scr = screen_handle.scr;
3734 73459770 mapscr* base_scr = screen_handle.base_scr;
3735
3736
4/4
✓ Branch 0 taken 60022668 times.
✓ Branch 1 taken 13437102 times.
✓ Branch 2 taken 13437102 times.
✓ Branch 3 taken 73459770 times.
73459770 if (type == -3 || type == -4)
3737 {
3738 26874204 y += playing_field_offset;
3739
3740
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
26874204 for(int32_t i = (base_scr->numFFC()-1); i >= 0; --i)
3741 {
3742 if (base_scr->ffcs[i].data == 0)
3743 continue;
3744
3745 if (screenscrolling && (base_scr->ffcs[i].flags & ffc_carryover) != 0 && screen_handle.screen != scrolling_hero_screen)
3746 continue; //If scrolling, only draw carryover ffcs from newscr and not oldscr.
3747
3748 base_scr->ffcs[i].draw_ffc(bmp, x, y, (type==-4));
3749 }
3750 return;
3751 }
3752
3753 73459770 x -= viewport.x;
3754 73459770 y -= viewport.y - playing_field_offset;
3755
3756 73459770 bool over = true, transp = false;
3757 73459770 int layer = screen_handle.layer;
3758
3759
7/8
✓ Branch 0 taken 53209080 times.
✓ Branch 1 taken 20250690 times.
✓ Branch 2 taken 13002524 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 32620006 times.
✓ Branch 5 taken 20589074 times.
✓ Branch 6 taken 3012681 times.
✓ Branch 7 taken 4235485 times.
73459770 switch(type ? type : layer)
3760 {
3761 case -2: //push blocks
3762
2/2
✓ Branch 0 taken 19182904 times.
✓ Branch 1 taken 13437102 times.
32620006 if (scr)
3763 {
3764
2/2
✓ Branch 0 taken 3376191104 times.
✓ Branch 1 taken 24639610 times.
3374940128 for(int32_t i=0; i<176; i++)
3765 {
3766 3376191104 int32_t mf=scr->sflag[i], mf2 = combobuf[scr->data[i]].flag;
3767
3768
10/10
✓ Branch 0 taken 3376022358 times.
✓ Branch 1 taken 168746 times.
✓ Branch 2 taken 3374584042 times.
✓ Branch 3 taken 1438316 times.
✓ Branch 4 taken 3373968191 times.
✓ Branch 5 taken 615851 times.
✓ Branch 6 taken 24420876 times.
✓ Branch 7 taken 3349547315 times.
✓ Branch 8 taken 42763031 times.
✓ Branch 9 taken 16297927 times.
3413238572 if(mf==mfPUSHUD || mf==mfPUSH4 || mf==mfPUSHED || ((mf>=mfPUSHLR)&&(mf<=mfPUSHRINS))
3769
6/8
✓ Branch 0 taken 3371086661 times.
✓ Branch 1 taken 21539346 times.
✓ Branch 2 taken 3371086661 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3371086661 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 37047468 times.
✓ Branch 7 taken 3334039193 times.
3373968191 || mf2==mfPUSHUD || mf2==mfPUSH4 || mf2==mfPUSHED || ((mf2>=mfPUSHLR)&&(mf2<=mfPUSHRINS)))
3770 {
3771
4/4
✓ Branch 0 taken 4727992 times.
✓ Branch 1 taken 692112 times.
✓ Branch 2 taken 3657 times.
✓ Branch 3 taken 4724335 times.
90946166 auto rpos = screenscrolling || ViewingMap ? rpos_t::None : POS_TO_RPOS(i, screen_handle.screen);
3772 5420104 draw_cmb_pos(bmp, x + COMBOX(i), y + COMBOY(i), rpos, scr->data[i], scr->cset[i], layer, true, false);
3773 5420104 }
3774 3355757224 }
3775 24639610 }
3776 38076712 return;
3777
3778 case -1: //over combo
3779
1/2
✓ Branch 0 taken 20589074 times.
✗ Branch 1 not taken.
20589074 if (scr)
3780 {
3781
2/2
✓ Branch 0 taken 3623677024 times.
✓ Branch 1 taken 20589074 times.
3644266098 for(int32_t i=0; i<176; i++)
3782 {
3783
2/2
✓ Branch 0 taken 3604406876 times.
✓ Branch 1 taken 19270148 times.
3623677024 if(combo_class_buf[combobuf[scr->data[i]].type].overhead)
3784 {
3785
4/4
✓ Branch 0 taken 15517569 times.
✓ Branch 1 taken 3752579 times.
✓ Branch 2 taken 22320 times.
✓ Branch 3 taken 15495249 times.
19270148 auto rpos = screenscrolling || ViewingMap ? rpos_t::None : POS_TO_RPOS(i, screen_handle.screen);
3786 19270148 draw_cmb_pos(bmp, x + COMBOX(i), y + COMBOY(i), rpos, scr->data[i], scr->cset[i], layer, true, false);
3787 19270148 }
3788 3623677024 }
3789 20589074 }
3790 20589074 return;
3791
3792 case 1:
3793 case 4:
3794 case 5:
3795 case 6:
3796
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 13002524 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
13002524 if(TransLayers || base_scr->layeropacity[layer-1]==255)
3797 {
3798
1/2
✓ Branch 0 taken 13002524 times.
✗ Branch 1 not taken.
13002524 if (scr)
3799 {
3800
2/2
✓ Branch 0 taken 11380329 times.
✓ Branch 1 taken 1622195 times.
13002524 if(base_scr->layeropacity[layer-1]!=255)
3801 1622195 transp = true;
3802 13002524 break;
3803 }
3804 }
3805 return;
3806
3807 case 2:
3808
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3012681 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3012681 if(TransLayers || base_scr->layeropacity[layer-1]==255)
3809 {
3810
1/2
✓ Branch 0 taken 3012681 times.
✗ Branch 1 not taken.
3012681 if (scr)
3811 {
3812
2/2
✓ Branch 0 taken 2793084 times.
✓ Branch 1 taken 219597 times.
3012681 if(base_scr->layeropacity[layer-1]!=255)
3813 219597 transp = true;
3814
3815
2/2
✓ Branch 0 taken 2883771 times.
✓ Branch 1 taken 128910 times.
3012681 if(XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3816 128910 over = false;
3817
3818 3012681 break;
3819 }
3820 }
3821 return;
3822
3823 case 3:
3824
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4235485 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4235485 if(TransLayers || base_scr->layeropacity[layer-1]==255)
3825 {
3826
1/2
✓ Branch 0 taken 4235485 times.
✗ Branch 1 not taken.
4235485 if (scr)
3827 {
3828
2/2
✓ Branch 0 taken 4161772 times.
✓ Branch 1 taken 73713 times.
4235485 if(base_scr->layeropacity[layer-1]!=255)
3829 73713 transp = true;
3830
3831
2/2
✓ Branch 0 taken 36655 times.
✓ Branch 1 taken 60483 times.
4235485 if(XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG)
3832
2/2
✓ Branch 0 taken 97138 times.
✓ Branch 1 taken 4138347 times.
4235485 && !XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3833 60483 over = false;
3834
3835 4235485 break;
3836 }
3837 }
3838 return;
3839 }
3840
3841 int start_x, end_x, start_y, end_y;
3842 20250690 get_bounds_for_draw_cmb_calls(bmp, x, y, start_x, end_x, start_y, end_y);
3843
2/2
✓ Branch 0 taken 20250690 times.
✓ Branch 1 taken 214672413 times.
234923103 for (int cy = start_y; cy < end_y; cy++)
3844 {
3845
2/2
✓ Branch 0 taken 3247876471 times.
✓ Branch 1 taken 214672413 times.
3462548884 for (int cx = start_x; cx < end_x; cx++)
3846 {
3847 3247876471 int i = cx + cy*16;
3848
4/4
✓ Branch 0 taken 2872677740 times.
✓ Branch 1 taken 375198731 times.
✓ Branch 2 taken 10227360 times.
✓ Branch 3 taken 2862450380 times.
3247876471 auto rpos = screenscrolling || ViewingMap ? rpos_t::None : POS_TO_RPOS(i, screen_handle.screen);
3849 3247876471 draw_cmb_pos(bmp, x + COMBOX(i), y + COMBOY(i), rpos, scr->data[i], scr->cset[i], layer, over, transp);
3850 3247876471 }
3851 214672413 }
3852 60022668 }
3853
3854 263970066 bool lenscheck(mapscr* scr, int layer)
3855 {
3856
4/4
✓ Branch 0 taken 263791118 times.
✓ Branch 1 taken 178948 times.
✓ Branch 2 taken 178948 times.
✓ Branch 3 taken 263970066 times.
263970066 if(layer < 0 || layer > 6) return true;
3857
2/2
✓ Branch 0 taken 254747832 times.
✓ Branch 1 taken 9222234 times.
263970066 if(get_qr(qr_OLD_LENS_LAYEREFFECT))
3858 {
3859
2/2
✓ Branch 0 taken 205809169 times.
✓ Branch 1 taken 48938663 times.
254747832 if(!layer) return true;
3860
8/8
✓ Branch 0 taken 34272155 times.
✓ Branch 1 taken 171537014 times.
✓ Branch 2 taken 258970 times.
✓ Branch 3 taken 34013185 times.
✓ Branch 4 taken 143758 times.
✓ Branch 5 taken 163336 times.
✓ Branch 6 taken 326536 times.
✓ Branch 7 taken 33830407 times.
205809169 if((layer==(int32_t)(scr->lens_layer&7)+1) && ((scr->lens_layer&llLENSSHOWS && !lensclk) || (scr->lens_layer&llLENSHIDES && lensclk)))
3861 489872 return false;
3862 205367421 }
3863 else
3864 {
3865
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9222234 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9222234 times.
9222234 if((lensclk ? scr->lens_hide : scr->lens_show) & (1<<layer))
3866 return false;
3867 }
3868 214589655 return true;
3869 263791118 }
3870
3871 153340548 void do_layer(BITMAP *bmp, int32_t type, const screen_handle_t& screen_handle, int32_t x, int32_t y)
3872 {
3873 153340548 bool showlayer = true;
3874 153340548 mapscr* base_scr = screen_handle.base_scr;
3875 153340548 int layer = screen_handle.layer;
3876
2/2
✓ Branch 0 taken 41368428 times.
✓ Branch 1 taken 111972120 times.
153340548 int target = type ? type : layer;
3877
3/4
✓ Branch 0 taken 111972120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19892812 times.
✓ Branch 3 taken 21475616 times.
153340548 switch(target)
3878 {
3879 case -2:
3880
1/2
✓ Branch 0 taken 19892812 times.
✗ Branch 1 not taken.
19892812 if(!show_layer_push)
3881 showlayer = false;
3882 19892812 break;
3883
3884 case -1:
3885
1/2
✓ Branch 0 taken 21475616 times.
✗ Branch 1 not taken.
21475616 if(!show_layer_over)
3886 showlayer = false;
3887 21475616 break;
3888
3889 case 1: case 2: case 3:
3890 case 4: case 5: case 6:
3891 111972120 showlayer = show_layers[target];
3892 111972120 break;
3893 }
3894
3895
2/2
✓ Branch 0 taken 41368428 times.
✓ Branch 1 taken 111972120 times.
153340548 if(!type)
3896 {
3897
2/2
✓ Branch 0 taken 111835922 times.
✓ Branch 1 taken 136198 times.
111972120 if(!lenscheck(base_scr,layer))
3898 136198 showlayer = false;
3899 111972120 }
3900
3901
2/2
✓ Branch 0 taken 136198 times.
✓ Branch 1 taken 153204350 times.
153340548 if(showlayer)
3902 {
3903
6/6
✓ Branch 0 taken 60078791 times.
✓ Branch 1 taken 93125559 times.
✓ Branch 2 taken 20306813 times.
✓ Branch 3 taken 39771978 times.
✓ Branch 4 taken 56123 times.
✓ Branch 5 taken 20250690 times.
153204350 if (screen_handle.scr && (type || !(base_scr->hidelayers & (1 << (layer)))))
3904 {
3905 60022668 do_scrolling_layer(bmp, type, screen_handle, x, y);
3906
4/4
✓ Branch 0 taken 20250690 times.
✓ Branch 1 taken 39771978 times.
✓ Branch 2 taken 19058365 times.
✓ Branch 3 taken 1192325 times.
60022668 if(!type && !get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3907
2/2
✓ Branch 0 taken 1191749 times.
✓ Branch 1 taken 576 times.
1192901 if(mblock2.draw(bmp,layer))
3908 576 do_primitives(bmp, SPLAYER_MOVINGBLOCK);
3909 60022668 }
3910 153204350 }
3911 153340548 }
3912
3913 101071755 void do_layer_primitives(BITMAP *bmp, int32_t layer)
3914 {
3915 101071755 bool showlayer = true;
3916
3917
2/4
✓ Branch 0 taken 101071755 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 101071755 times.
101071755 if(layer >= 0 && layer <= 6)
3918 {
3919 101071755 showlayer = show_layers[layer];
3920
3921
2/2
✓ Branch 0 taken 100945153 times.
✓ Branch 1 taken 126602 times.
101071755 if(!lenscheck(origin_scr,layer))
3922 126602 showlayer = false;
3923 101071755 }
3924
3925
2/2
✓ Branch 0 taken 126602 times.
✓ Branch 1 taken 100945153 times.
101071755 if (showlayer)
3926 100945153 do_primitives(bmp, layer);
3927 101071755 }
3928
3929 // Called by do_walkflags
3930 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,int32_t xofs,int32_t yofs, word cmbdat,int32_t lyr)
3931 {
3932 newcombo const &c = combobuf[cmbdat];
3933
3934 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
3935
3936 int32_t xx = x-xofs;
3937 int32_t yy = y+playing_field_offset-yofs;
3938
3939 int32_t bridgedetected = 0;
3940
3941 for(int32_t i=0; i<4; i++)
3942 {
3943 int32_t tx=((i&2)<<2)+xx - viewport.x;
3944 int32_t ty=((i&1)<<3)+yy - viewport.y;
3945 int32_t tx2=((i&2)<<2)+x - viewport.x;
3946 int32_t ty2=((i&1)<<3)+y - viewport.y;
3947 for (int32_t j = lyr-1; j <= 1; j++)
3948 {
3949 if (get_qr(qr_OLD_BRIDGE_COMBOS))
3950 {
3951 if (combobuf[MAPCOMBO2(j,tx2,ty2)].type == cBRIDGE && !_walkflag_layer(tx2,ty2,j))
3952 {
3953 bridgedetected |= (1<<i);
3954 }
3955 }
3956 else
3957 {
3958 if (combobuf[MAPCOMBO2(j,tx2,ty2)].type == cBRIDGE && _effectflag_layer(tx2,ty2,j))
3959 {
3960 bridgedetected |= (1<<i);
3961 }
3962 }
3963 }
3964 if ((bridgedetected & (1<<i)))
3965 {
3966 if (i >= 3) break;
3967 else continue;
3968 }
3969 bool doladdercheck = true;
3970
3971 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
3972 {
3973 for(int32_t k=0; k<8; k+=2)
3974 for(int32_t j=0; j<8; j+=2)
3975 if(((k+j)/2)%2)
3976 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,makecol(85,85,255));
3977 }
3978 if (iswater_type(c.type) && !DRIEDLAKE && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) //Yes, I realize this is horribly inaccurate; the alternative is the game chugging every time you turn on walk cheats.
3979 {
3980 if (get_qr(qr_NO_SOLID_SWIM)) doladdercheck = false;
3981 if((lyr==0 || (get_qr(qr_WATER_ON_LAYER_1) && lyr == 1) || (get_qr(qr_WATER_ON_LAYER_2) && lyr == 2)) && get_qr(qr_DROWN))
3982 rectfill(dest,tx,ty,tx+7,ty+7,makecol(85,85,255));
3983 else rectfill(dest,tx,ty,tx+7,ty+7,makecol(170,170,170));
3984 }
3985
3986 if(c.walk&(1<<i) && !(iswater_type(c.type) && DRIEDLAKE) && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) // Check for dried lake (watertype && not water)
3987 {
3988 if(c.type==cLADDERHOOKSHOT && isstepable(cmbdat) && ishookshottable(xx,yy))
3989 {
3990 for(int32_t k=0; k<8; k+=2)
3991 for(int32_t j=0; j<8; j+=2)
3992 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,((k+j)/2)%2 ? makecol(165,105,8) : makecol(170,170,170));
3993 }
3994 else
3995 {
3996 int32_t color = makecol(178,36,36);
3997
3998 if(isstepable(cmbdat)&& (!doladdercheck))
3999 color=makecol(165,105,8);
4000 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(xx,yy))
4001 color=makecol(170,170,170);
4002
4003 rectfill(dest,tx,ty,tx+7,ty+7,color);
4004 }
4005 }
4006 }
4007
4008 // Draw damage combos
4009 bool dmg = combo_class_buf[combobuf[MAPCOMBO2(-1,xx,yy)].type].modify_hp_amount
4010 || combo_class_buf[combobuf[MAPCOMBO2(0,xx,yy)].type].modify_hp_amount
4011 || combo_class_buf[combobuf[MAPCOMBO2(1,xx,yy)].type].modify_hp_amount;
4012
4013 if(dmg)
4014 {
4015 int32_t color = makecol(255,255,0);
4016 if (bridgedetected <= 0)
4017 {
4018 for(int32_t k=0; k<16; k+=2)
4019 for(int32_t j=0; j<16; j+=2)
4020 if(((k+j)/2)%2)
4021 {
4022 int32_t x0 = x - viewport.x;
4023 int32_t y0 = y - viewport.y;
4024 rectfill(dest,x0+k,y0+j,x0+k+1,y0+j+1,color);
4025 }
4026 }
4027 else
4028 {
4029 for(int32_t i=0; i<4; i++)
4030 {
4031 if (!(bridgedetected & (1<<i)))
4032 {
4033 int32_t tx=((i&2)<<2)+x - viewport.x;
4034 int32_t ty=((i&1)<<3)+y - viewport.y;
4035 for(int32_t k=0; k<8; k+=2)
4036 for(int32_t j=0; j<8; j+=2)
4037 if((k+j)%4 < 2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,color);
4038 }
4039 }
4040 }
4041 }
4042 }
4043 static void put_walkflags_a5(int32_t x, int32_t y, word cmbdat, int32_t lyr)
4044 {
4045 ALLEGRO_COLOR col_solid = al_map_rgba(178,36,36,info_opacity);
4046 ALLEGRO_COLOR col_water1 = al_map_rgba(85,85,255,info_opacity);
4047 ALLEGRO_COLOR col_lhook = al_map_rgba(170,170,170,info_opacity);
4048 ALLEGRO_COLOR col_stepable = al_map_rgba(165,105,8,info_opacity);
4049 ALLEGRO_COLOR col_dmg = al_map_rgba(255,255,0,info_opacity);
4050 newcombo const &c = combobuf[cmbdat];
4051
4052 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
4053
4054 int32_t xx = x-viewport.x;
4055 int32_t yy = y+playing_field_offset-viewport.y;
4056
4057 int32_t bridgedetected = 0;
4058
4059 // Draw damage combos
4060 bool dmg = combo_class_buf[c.type].modify_hp_amount;
4061
4062 for(int32_t i=0; i<4; i++)
4063 {
4064 int32_t tx=((i&2)<<2)+xx;
4065 int32_t ty=((i&1)<<3)+yy;
4066 int32_t tx2=((i&2)<<2)+x;
4067 int32_t ty2=((i&1)<<3)+y;
4068 for (int32_t m = lyr-1; m <= 1; m++)
4069 {
4070 if (get_qr(qr_OLD_BRIDGE_COMBOS))
4071 {
4072 if (m >= 0 && combobuf[MAPCOMBO2(m, tx2, ty2)].type == cBRIDGE && !_walkflag_layer(tx2, ty2, m))
4073 {
4074 bridgedetected |= (1<<i);
4075 }
4076 }
4077 else
4078 {
4079 if (m >= 0 && combobuf[MAPCOMBO2(m, tx2, ty2)].type == cBRIDGE && _effectflag_layer(tx2, ty2, m))
4080 {
4081 bridgedetected |= (1<<i);
4082 }
4083 }
4084 }
4085 if ((bridgedetected & (1<<i)))
4086 continue;
4087 bool doladdercheck = true;
4088
4089 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
4090 {
4091 for(int32_t k=0; k<8; k+=2)
4092 for(int32_t j=0; j<8; j+=2)
4093 if(((k+j)/2)%2)
4094 al_draw_filled_rectangle(tx+k,ty+j,tx+k+2,ty+j+2,col_water1);
4095 }
4096 if (iswater_type(c.type) && !DRIEDLAKE && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) //Yes, I realize this is horribly inaccurate; the alternative is the game chugging every time you turn on walk cheats.
4097 {
4098 if (get_qr(qr_NO_SOLID_SWIM)) doladdercheck = false;
4099 if((lyr==0 || (get_qr(qr_WATER_ON_LAYER_1) && lyr == 1) || (get_qr(qr_WATER_ON_LAYER_2) && lyr == 2)) && get_qr(qr_DROWN))
4100 al_draw_filled_rectangle(tx,ty,tx+8,ty+8,col_water1);
4101 else al_draw_filled_rectangle(tx,ty,tx+8,ty+8,col_lhook);
4102 }
4103
4104 if(c.walk&(1<<i) && !(iswater_type(c.type) && DRIEDLAKE) && !((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)) && c.type == cWATER)))) // Check for dried lake (watertype && not water)
4105 {
4106 if(c.type==cLADDERHOOKSHOT && isstepable(cmbdat) && ishookshottable(xx,yy))
4107 {
4108 for(int32_t k=0; k<8; k+=2)
4109 for(int32_t j=0; j<8; j+=2)
4110 al_draw_filled_rectangle(tx+k,ty+j,tx+k+2,ty+j+2,((k+j)/2)%2 ? col_stepable : col_lhook);
4111 }
4112 else
4113 {
4114 ALLEGRO_COLOR* color = &col_solid;
4115
4116 if(isstepable(cmbdat)&& (!doladdercheck))
4117 color=&col_stepable;
4118 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(xx,yy))
4119 color=&col_lhook;
4120
4121 al_draw_filled_rectangle(tx,ty,tx+8,ty+8,*color);
4122 }
4123 }
4124
4125 if(dmg)
4126 {
4127 for(int32_t k=0; k<8; k+=2)
4128 for(int32_t j=0; j<8; j+=2)
4129 if((k+j)%4 < 2) al_draw_filled_rectangle(tx+k,ty+j,tx+k+2,ty+j+2,col_dmg);
4130 }
4131 }
4132 }
4133
4134 void put_effectflags(BITMAP *dest,int32_t x,int32_t y,int32_t xofs,int32_t yofs, word cmbdat,int32_t lyr)
4135 {
4136 newcombo const &c = combobuf[cmbdat];
4137
4138 int32_t xx = x-xofs-viewport.x;
4139 int32_t yy = y+playing_field_offset-yofs-viewport.y;
4140
4141 for(int32_t i=0; i<4; i++)
4142 {
4143 int32_t tx=((i&2)<<2)+xx;
4144 int32_t ty=((i&1)<<3)+yy;
4145
4146 if(((c.walk>>4)&(1<<i)) && c.type != cNONE)
4147 {
4148 int32_t color = vc(10);
4149
4150 rectfill(dest,tx,ty,tx+7,ty+7,color);
4151 }
4152 }
4153 }
4154 static void put_effectflags_a5(int32_t x, int32_t y, word cmbdat, int32_t lyr)
4155 {
4156 ALLEGRO_COLOR col_eff = al_map_rgba(85,255,85,info_opacity);
4157 newcombo const &c = combobuf[cmbdat];
4158
4159 int32_t xx = x-viewport.x;
4160 int32_t yy = y+playing_field_offset-viewport.y;
4161
4162 for(int32_t i=0; i<4; i++)
4163 {
4164 int32_t tx=((i&2)<<2)+xx;
4165 int32_t ty=((i&1)<<3)+yy;
4166
4167 if(((c.walk>>4)&(1<<i)) && c.type != cNONE)
4168 {
4169 al_draw_filled_rectangle(tx,ty,tx+8,ty+8,col_eff);
4170 }
4171 }
4172 }
4173
4174 void draw_ladder_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
4175 {
4176 for(auto cx = 0; cx < 256; cx += 16)
4177 {
4178 for(auto cy = 0; cy < 176; cy += 16)
4179 {
4180 if(isSVLadder(cx,cy))
4181 {
4182 auto nx = cx+x, ny = cy+y;
4183 if(cy && !isSVLadder(cx,cy-16))
4184 line(dest,nx,ny,nx+15,ny,c);
4185 rectfill(dest,nx,ny,nx+3,ny+15,c);
4186 rectfill(dest,nx+12,ny,nx+15,ny+15,c);
4187 rectfill(dest,nx+4,ny+2,nx+11,ny+5,c);
4188 rectfill(dest,nx+4,ny+10,nx+11,ny+13,c);
4189 }
4190 else if(isSVPlatform(cx,cy))
4191 {
4192 line(dest,cx+x,cy+y,cx+x+15,cy+y,c);
4193 }
4194 }
4195 }
4196 }
4197 void draw_ladder_platform_a5(int32_t x, int32_t y, ALLEGRO_COLOR c)
4198 {
4199 for(auto cx = 0; cx < 256; cx += 16)
4200 {
4201 for(auto cy = 0; cy < 176; cy += 16)
4202 {
4203 if(isSVLadder(cx,cy))
4204 {
4205 auto nx = cx+x, ny = cy+y;
4206 if(cy && !isSVLadder(cx,cy-16))
4207 al_draw_line(nx,ny,nx+15,ny,c,1);
4208 al_draw_filled_rectangle(nx,ny,nx+4,ny+16,c);
4209 al_draw_filled_rectangle(nx+12,ny,nx+16,ny+16,c);
4210 al_draw_filled_rectangle(nx+4,ny+2,nx+12,ny+6,c);
4211 al_draw_filled_rectangle(nx+4,ny+10,nx+12,ny+14,c);
4212 }
4213 else if(isSVPlatform(cx,cy))
4214 {
4215 al_draw_line(cx+x,cy+y,cx+x+15,cy+y,c,1);
4216 }
4217 }
4218 }
4219 }
4220
4221 // Walkflags L4 cheat
4222 void do_walkflags(const screen_handles_t& screen_handles, int32_t x, int32_t y)
4223 {
4224 if (!show_walkflags)
4225 return;
4226
4227 start_info_bmp();
4228
4229 mapscr* scr = screen_handles[0].scr;
4230 for(int32_t i=0; i<176; i++)
4231 {
4232 put_walkflags_a5(((i&15)<<4) + x, (i&0xF0) + y, scr->data[i], 0);
4233 }
4234
4235 for(int32_t k=0; k<2; k++)
4236 {
4237 scr = screen_handles[k + 1].scr;
4238
4239 if (scr)
4240 {
4241 for(int32_t i=0; i<176; i++)
4242 {
4243 put_walkflags_a5(((i&15)<<4) + x, (i&0xF0) + y, scr->data[i], k%2+1);
4244 }
4245 }
4246 }
4247
4248 end_info_bmp();
4249 }
4250
4251 void do_walkflags(int32_t x, int32_t y)
4252 {
4253 if (!show_walkflags)
4254 return;
4255
4256 x += -viewport.x;
4257 y += playing_field_offset - viewport.y;
4258
4259 start_info_bmp();
4260
4261 draw_ladder_platform_a5(x,y,al_map_rgba(165,105,8,info_opacity));
4262 draw_solid_objects_a5(x,y,al_map_rgba(178,36,36,info_opacity));
4263 draw_slopes_a5(x,y,al_map_rgba(255,85,255,info_opacity));
4264
4265 end_info_bmp();
4266 }
4267
4268 // Effectflags L4 cheat
4269 void do_effectflags(mapscr* scr, int32_t x, int32_t y)
4270 {
4271 if(show_effectflags)
4272 {
4273 start_info_bmp();
4274
4275 for(int32_t i=0; i<176; i++)
4276 {
4277 put_effectflags_a5(((i&15)<<4) + x, (i&0xF0) + y, scr->data[i], 0);
4278 }
4279
4280 end_info_bmp();
4281 }
4282 }
4283
4284 272141 void calc_darkroom_combos(mapscr* scr, int offx, int offy)
4285 {
4286 272141 int map = scr->map;
4287 272141 int screen = scr->screen;
4288
4289
2/2
✓ Branch 0 taken 1904987 times.
✓ Branch 1 taken 272141 times.
2177128 for(int32_t lyr = 0; lyr < 7; ++lyr)
4290 {
4291 1904987 mapscr* scr = get_scr_layer(map, screen, lyr);
4292
2/2
✓ Branch 0 taken 780869 times.
✓ Branch 1 taken 1124118 times.
1904987 if (!scr->is_valid()) continue;
4293
4294
2/2
✓ Branch 0 taken 137432944 times.
✓ Branch 1 taken 780869 times.
138213813 for(int32_t q = 0; q < 176; ++q)
4295 {
4296 137432944 newcombo const& cmb = combobuf[scr->data[q]];
4297
2/2
✓ Branch 0 taken 136828325 times.
✓ Branch 1 taken 604619 times.
137432944 if(cmb.type == cTORCH)
4298 {
4299 604619 do_torch_combo(cmb, COMBOX(q)+8+offx, COMBOY(q)+8+offy, darkscr_bmp);
4300 604619 }
4301 137432944 }
4302 780869 }
4303 272141 }
4304
4305 272141 void calc_darkroom_ffcs(mapscr* scr, int offx, int offy)
4306 {
4307 272141 word c = scr->numFFC();
4308
2/2
✓ Branch 0 taken 537406 times.
✓ Branch 1 taken 272141 times.
809547 for(int q = 0; q < c; ++q)
4309 {
4310 537406 newcombo const& cmb = combobuf[scr->ffcs[q].data];
4311
2/2
✓ Branch 0 taken 522598 times.
✓ Branch 1 taken 14808 times.
537406 if(cmb.type == cTORCH)
4312 {
4313 14808 int cx = scr->ffcs[q].x.getInt()+(scr->ffEffectWidth(q)/2)+offx;
4314 14808 int cy = (scr->ffcs[q].y.getInt())+(scr->ffEffectHeight(q)/2)+offy;
4315 14808 do_torch_combo(cmb, cx, cy, darkscr_bmp);
4316 14808 }
4317 537406 }
4318 272141 }
4319
4320 struct nearby_screen_t
4321 {
4322 int screen;
4323 int offx;
4324 int offy;
4325 screen_handles_t screen_handles;
4326 };
4327 typedef std::vector<nearby_screen_t> nearby_screens_t;
4328
4329 15186862 static nearby_screens_t get_nearby_screens_non_scrolling_region()
4330 {
4331 15186862 nearby_screens_t nearby_screens;
4332
4333 15186862 mapscr* base_scr = origin_scr;
4334
1/2
✓ Branch 0 taken 15186862 times.
✗ Branch 1 not taken.
15186862 auto& nearby_screen = nearby_screens.emplace_back();
4335 15186862 nearby_screen.screen = cur_screen;
4336
1/2
✓ Branch 0 taken 15186862 times.
✗ Branch 1 not taken.
15186862 nearby_screen.screen_handles = create_screen_handles(base_scr);
4337
4338 15186862 return nearby_screens;
4339
1/2
✓ Branch 0 taken 15186862 times.
✗ Branch 1 not taken.
15186862 }
4340
4341 48296 static nearby_screens_t get_nearby_screens_scrolling_region()
4342 {
4343 48296 nearby_screens_t nearby_screens;
4344
4345
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_x0 = viewport.left() / 256;
4346
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_x1 = (viewport.right() - 1) / 256;
4347
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_y0 = viewport.top() / 176;
4348
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 int screens_y1 = (viewport.bottom() - 1) / 176;
4349
4350
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_x0 = std::clamp(screens_x0, 0, 15);
4351
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_x1 = std::clamp(screens_x1, 0, 15);
4352
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_y0 = std::clamp(screens_y0, 0, 8);
4353
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 screens_y1 = std::clamp(screens_y1, 0, 8);
4354
4355
2/2
✓ Branch 0 taken 48296 times.
✓ Branch 1 taken 79928 times.
128224 for (int x = screens_x0; x <= screens_x1; x++)
4356 {
4357
2/2
✓ Branch 0 taken 169672 times.
✓ Branch 1 taken 79928 times.
249600 for (int y = screens_y0; y <= screens_y1; y++)
4358 {
4359 169672 int screen = cur_screen + x + y*16;
4360
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 if (!is_in_current_region(screen)) continue;
4361
4362
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 mapscr* base_scr = get_scr(screen);
4363
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 if (!base_scr->is_valid()) continue;
4364
4365
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 auto [offx, offy] = translate_screen_coordinates_to_world(screen);
4366
4367
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 auto& nearby_screen = nearby_screens.emplace_back();
4368 169672 nearby_screen.screen = screen;
4369 169672 nearby_screen.offx = offx;
4370 169672 nearby_screen.offy = offy;
4371
1/2
✓ Branch 0 taken 169672 times.
✗ Branch 1 not taken.
169672 nearby_screen.screen_handles = create_screen_handles(base_scr);
4372 169672 }
4373 79928 }
4374
4375 48296 return nearby_screens;
4376
1/2
✓ Branch 0 taken 48296 times.
✗ Branch 1 not taken.
48296 }
4377
4378 3658 static nearby_screens_t get_nearby_screens_smooth_maze()
4379 {
4380 3658 nearby_screens_t nearby_screens;
4381
4382
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_x0 = viewport.left() / 256;
4383
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_x1 = (viewport.right() - 1) / 256;
4384
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_y0 = viewport.top() / 176;
4385
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 int screens_y1 = (viewport.bottom() - 1) / 176;
4386
4387
2/4
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
3658 if (viewport.left() < 0) screens_x0--;
4388
2/4
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
3658 if (viewport.top() < 0) screens_y0--;
4389
4390
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 7308 times.
10966 for (int x = screens_x0; x <= screens_x1; x++)
4391 {
4392
2/2
✓ Branch 0 taken 18600 times.
✓ Branch 1 taken 7308 times.
25908 for (int y = screens_y0; y <= screens_y1; y++)
4393 {
4394 18600 int screen = -1;
4395 mapscr* base_scr;
4396 int offx, offy;
4397
4398 18600 mapscr* maze_scr = maze_state.scr;
4399 18600 int maze_screen = maze_scr->screen;
4400
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 int maze_screen_x = get_region_relative_dx(maze_screen);
4401
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 int maze_screen_y = get_region_relative_dy(maze_screen);
4402 18600 int maze_screen_dx = x - maze_screen_x;
4403 18600 int maze_screen_dy = y - maze_screen_y;
4404 18600 int exitdir = maze_scr->exitdir;
4405
4406 bool should_draw_maze_screen;
4407
2/2
✓ Branch 0 taken 9052 times.
✓ Branch 1 taken 9548 times.
18600 if (maze_state.lost)
4408 {
4409 9548 should_draw_maze_screen = true;
4410 9548 }
4411 else
4412 {
4413 9052 should_draw_maze_screen = true;
4414
4/6
✓ Branch 0 taken 9052 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6844 times.
✓ Branch 3 taken 2208 times.
✓ Branch 4 taken 6844 times.
✗ Branch 5 not taken.
9052 should_draw_maze_screen &= XY_DELTA_TO_DIR(maze_screen_dx, 0) != exitdir && XY_DELTA_TO_DIR(0, maze_screen_dy) != exitdir;
4415
2/2
✓ Branch 0 taken 3850 times.
✓ Branch 1 taken 5202 times.
9052 if (maze_state.enter_dir != dir_invalid)
4416
4/6
✓ Branch 0 taken 3850 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3304 times.
✓ Branch 3 taken 546 times.
✓ Branch 4 taken 3304 times.
✗ Branch 5 not taken.
3850 should_draw_maze_screen &= XY_DELTA_TO_DIR(maze_screen_dx, 0) != maze_state.enter_dir && XY_DELTA_TO_DIR(0, maze_screen_dy) != maze_state.enter_dir;
4417 }
4418
4419
2/2
✓ Branch 0 taken 16048 times.
✓ Branch 1 taken 2552 times.
18600 if (should_draw_maze_screen)
4420 {
4421 16048 screen = maze_state.scr->screen;
4422 16048 base_scr = maze_state.scr;
4423
1/2
✓ Branch 0 taken 16048 times.
✗ Branch 1 not taken.
16048 std::tie(offx, offy) = translate_screen_coordinates_to_world(cur_screen + x + y*16);
4424 16048 }
4425
4426
2/2
✓ Branch 0 taken 16048 times.
✓ Branch 1 taken 2552 times.
18600 if (screen == -1)
4427 {
4428 2552 screen = cur_screen + x + y*16;
4429
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 if (!is_in_current_region(screen)) continue;
4430
4431
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 base_scr = get_scr(screen);
4432
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 if (!base_scr->is_valid()) continue;
4433
4434
1/2
✓ Branch 0 taken 2552 times.
✗ Branch 1 not taken.
2552 std::tie(offx, offy) = translate_screen_coordinates_to_world(screen);
4435 2552 }
4436
4437
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 auto& nearby_screen = nearby_screens.emplace_back();
4438 18600 nearby_screen.screen = screen;
4439 18600 nearby_screen.offx = offx;
4440 18600 nearby_screen.offy = offy;
4441
1/2
✓ Branch 0 taken 18600 times.
✗ Branch 1 not taken.
18600 nearby_screen.screen_handles = create_screen_handles(base_scr);
4442 18600 }
4443 7308 }
4444
4445 3658 return nearby_screens;
4446
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 }
4447
4448 15238816 static nearby_screens_t get_nearby_screens()
4449 {
4450
4/4
✓ Branch 0 taken 9214 times.
✓ Branch 1 taken 15229602 times.
✓ Branch 2 taken 3658 times.
✓ Branch 3 taken 5556 times.
15238816 if (maze_state.active && maze_state.loopy)
4451 3658 return get_nearby_screens_smooth_maze();
4452
4453
2/2
✓ Branch 0 taken 48296 times.
✓ Branch 1 taken 15186862 times.
15235158 if (is_in_scrolling_region())
4454 48296 return get_nearby_screens_scrolling_region();
4455
4456 15186862 return get_nearby_screens_non_scrolling_region();
4457 15238816 }
4458
4459 198137768 static void for_every_nearby_screen(const nearby_screens_t& nearby_screens, const std::function <void (screen_handles_t, int, int, int)>& fn)
4460 {
4461
2/2
✓ Branch 0 taken 199922370 times.
✓ Branch 1 taken 198137768 times.
398060138 for (auto& nearby_screen : nearby_screens)
4462 199922370 fn(nearby_screen.screen_handles, nearby_screen.screen, nearby_screen.offx, nearby_screen.offy);
4463 198137768 }
4464
4465 121910528 static void draw_msgstr(byte layer, BITMAP* dest = nullptr)
4466 {
4467
2/2
✓ Branch 0 taken 15238816 times.
✓ Branch 1 taken 106671712 times.
121910528 if(layer != msgstr_layer) return;
4468
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 if(!dest) dest = framebuf;
4469
4470
2/2
✓ Branch 0 taken 674112 times.
✓ Branch 1 taken 14564704 times.
15238816 if(!(msg_bg_display_buf->clip))
4471 {
4472 674112 blit_msgstr_bg(dest,0,0,0,playing_field_offset,256,176);
4473 674112 }
4474
4475
2/2
✓ Branch 0 taken 674112 times.
✓ Branch 1 taken 14564704 times.
15238816 if(!(msg_portrait_display_buf->clip))
4476 {
4477 674112 blit_msgstr_prt(dest,0,0,0,playing_field_offset,256,176);
4478 674112 }
4479
4480
2/2
✓ Branch 0 taken 686526 times.
✓ Branch 1 taken 14552290 times.
15238816 if(!(msg_txt_display_buf->clip))
4481 {
4482 686526 blit_msgstr_fg(dest,0,0,0,playing_field_offset,256,176);
4483 686526 }
4484 121910528 }
4485
4486 static void putscrdoors(const nearby_screens_t& nearby_screens, BITMAP *dest, int32_t x, int32_t y);
4487
4488 60955264 static void set_draw_screen_clip(BITMAP* bmp)
4489 {
4490 60955264 set_clip_rect(bmp, draw_screen_clip_rect_x1, draw_screen_clip_rect_y1, draw_screen_clip_rect_x2, draw_screen_clip_rect_y2);
4491 60955264 }
4492
4493 45237922 void draw_screen(bool showhero, bool runGeneric)
4494 {
4495 45237922 clear_info_bmp();
4496
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45237922 times.
45237922 if((GameFlags & (GAMEFLAG_SCRIPTMENU_ACTIVE|GAMEFLAG_F6SCRIPT_ACTIVE))!=0)
4497 {
4498 FFCore.doScriptMenuDraws();
4499 return;
4500 }
4501
4502
2/2
✓ Branch 0 taken 30581643 times.
✓ Branch 1 taken 14656279 times.
45237922 if(runGeneric) FFCore.runGenericPassiveEngine(SCR_TIMING_PRE_DRAW);
4503
4504 45237922 clear_bitmap(framebuf);
4505 45237922 clear_clip_rect(framebuf);
4506
4507 45237922 int32_t cmby2=0;
4508
4509 // Draw some background layers
4510 45237922 clear_bitmap(scrollbuf);
4511
4512 45237922 auto nearby_screens = get_nearby_screens();
4513
4514 // Handle layer 2/3 possibly being background layers.
4515
1/2
✓ Branch 0 taken 45237922 times.
✗ Branch 1 not taken.
60613056 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4516 15375134 mapscr* base_scr = screen_handles[0].base_scr;
4517
2/2
✓ Branch 0 taken 15247852 times.
✓ Branch 1 taken 127282 times.
15375134 if (XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4518 127282 do_layer(scrollbuf, 0, screen_handles[2], offx, offy);
4519 15375134 });
4520
4521
2/2
✓ Branch 0 taken 127282 times.
✓ Branch 1 taken 45110640 times.
45237922 if (XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4522 {
4523
1/2
✓ Branch 0 taken 127282 times.
✗ Branch 1 not taken.
127282 do_layer_primitives(scrollbuf, 2);
4524
1/2
✓ Branch 0 taken 127282 times.
✗ Branch 1 not taken.
127282 particles.draw(scrollbuf, true, 2);
4525 127282 }
4526
2/2
✓ Branch 0 taken 15238816 times.
✓ Branch 1 taken 29999106 times.
45237922 _do_current_ffc_layer(scrollbuf, -2);
4527
2/2
✓ Branch 0 taken 127282 times.
✓ Branch 1 taken 15111534 times.
15238816 if (XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4528
1/2
✓ Branch 0 taken 127282 times.
✗ Branch 1 not taken.
127282 draw_msgstr(2, scrollbuf);
4529
4530
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
30613950 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4531 15375134 mapscr* base_scr = screen_handles[0].base_scr;
4532
2/2
✓ Branch 0 taken 15282474 times.
✓ Branch 1 taken 92660 times.
15375134 if (XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4533 92660 do_layer(scrollbuf, 0, screen_handles[3], offx, offy);
4534 15375134 });
4535
4536
2/2
✓ Branch 0 taken 92660 times.
✓ Branch 1 taken 15146156 times.
15238816 if (XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4537 {
4538
1/2
✓ Branch 0 taken 92660 times.
✗ Branch 1 not taken.
92660 do_layer_primitives(scrollbuf, 3);
4539
1/2
✓ Branch 0 taken 92660 times.
✗ Branch 1 not taken.
92660 particles.draw(scrollbuf, true, 3);
4540 92660 }
4541
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 _do_current_ffc_layer(scrollbuf, -3);
4542
2/2
✓ Branch 0 taken 92660 times.
✓ Branch 1 taken 15146156 times.
15238816 if (XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4543
1/2
✓ Branch 0 taken 92660 times.
✗ Branch 1 not taken.
92660 draw_msgstr(3, scrollbuf);
4544
4545 // Draw the main combo screens ("layer 0").
4546
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
30613950 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4547 15375134 mapscr* base_scr = screen_handles[0].base_scr;
4548
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15375134 times.
15375134 if (lenscheck(base_scr, 0))
4549 {
4550 15375134 putscr(base_scr, scrollbuf, offx, offy + playing_field_offset);
4551 15375134 }
4552 15375134 });
4553
4554
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15238816 times.
15238816 if (lenscheck(hero_scr, 0))
4555 {
4556
2/2
✓ Branch 0 taken 454382 times.
✓ Branch 1 taken 14784434 times.
15238816 if(!get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4557
3/4
✓ Branch 0 taken 454382 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4136 times.
✓ Branch 3 taken 450246 times.
458518 if(mblock2.draw(scrollbuf,0))
4558
1/2
✓ Branch 0 taken 4136 times.
✗ Branch 1 not taken.
4136 do_primitives(scrollbuf, SPLAYER_MOVINGBLOCK);
4559 15238816 }
4560
4561 // Lens hints, then primitives, then particles.
4562
6/10
✓ Branch 0 taken 15228787 times.
✓ Branch 1 taken 10029 times.
✓ Branch 2 taken 15228787 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15228787 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 5876 times.
✓ Branch 9 taken 4153 times.
15238816 if((lensclk || (get_debug() && zc_getkey(KEY_L))) && !get_qr(qr_OLDLENSORDER))
4563 {
4564
1/2
✓ Branch 0 taken 5876 times.
✗ Branch 1 not taken.
5876 draw_lens_under(scrollbuf, false);
4565
1/2
✓ Branch 0 taken 5876 times.
✗ Branch 1 not taken.
5876 do_primitives(scrollbuf, SPLAYER_LENS_UNDER_1);
4566 5876 }
4567
4568
2/4
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15238816 times.
✗ Branch 3 not taken.
15238816 if(show_layers[0] && lenscheck(hero_scr,0))
4569
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 do_primitives(scrollbuf, 0);
4570
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 particles.draw(scrollbuf, true, 0);
4571
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 _do_current_ffc_layer(scrollbuf, 0);
4572
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 draw_msgstr(0, scrollbuf);
4573
4574
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 set_draw_screen_clip(scrollbuf);
4575
4576
2/2
✓ Branch 0 taken 14895557 times.
✓ Branch 1 taken 343259 times.
15238816 if(!(get_qr(qr_LAYER12UNDERCAVE)))
4577 {
4578
4/4
✓ Branch 0 taken 14893683 times.
✓ Branch 1 taken 1874 times.
✓ Branch 2 taken 53440 times.
✓ Branch 3 taken 14805491 times.
29754488 if(showhero &&
4579
4/6
✓ Branch 0 taken 14893683 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14858931 times.
✓ Branch 3 taken 34752 times.
✓ Branch 4 taken 14858931 times.
✗ Branch 5 not taken.
14893683 ((Hero.getAction()==climbcovertop)||(Hero.getAction()==climbcoverbottom)))
4580 {
4581
3/4
✓ Branch 0 taken 88192 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 53440 times.
✓ Branch 3 taken 34752 times.
88192 if(Hero.getAction()==climbcovertop)
4582 {
4583 34752 cmby2=16;
4584 34752 }
4585
2/4
✓ Branch 0 taken 53440 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 53440 times.
53440 else if(Hero.getAction()==climbcoverbottom)
4586 {
4587 53440 cmby2=-16;
4588 53440 }
4589
4590
1/2
✓ Branch 0 taken 88192 times.
✗ Branch 1 not taken.
88192 decorations.draw2(scrollbuf,true);
4591
1/2
✓ Branch 0 taken 88192 times.
✗ Branch 1 not taken.
88192 Hero.draw(scrollbuf);
4592
1/2
✓ Branch 0 taken 88192 times.
✗ Branch 1 not taken.
88192 decorations.draw(scrollbuf,true);
4593
2/4
✓ Branch 0 taken 88192 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88192 times.
✗ Branch 3 not taken.
88192 int32_t ccx = (int32_t)Hero.getClimbCoverX();
4594
2/4
✓ Branch 0 taken 88192 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88192 times.
✗ Branch 3 not taken.
88192 int32_t ccy = (int32_t)Hero.getClimbCoverY();
4595
4596
3/6
✓ Branch 0 taken 88192 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88192 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88192 times.
✗ Branch 5 not taken.
88192 overcombo(scrollbuf,ccx-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy+cmby2),MAPCSET(ccx,ccy+cmby2));
4597
3/6
✓ Branch 0 taken 88192 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88192 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88192 times.
✗ Branch 5 not taken.
88192 putcombo(scrollbuf,ccx-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy),MAPCSET(ccx,ccy));
4598
4599
4/6
✓ Branch 0 taken 88192 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88192 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15040 times.
✓ Branch 5 taken 73152 times.
88192 if(int32_t(Hero.getX())&15)
4600 {
4601
3/6
✓ Branch 0 taken 15040 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15040 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15040 times.
✗ Branch 5 not taken.
15040 overcombo(scrollbuf,ccx+16-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy+cmby2),MAPCSET(ccx+16,ccy+cmby2));
4602
3/6
✓ Branch 0 taken 15040 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15040 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15040 times.
✗ Branch 5 not taken.
15040 putcombo(scrollbuf,ccx+16-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy),MAPCSET(ccx+16,ccy));
4603 15040 }
4604 88192 }
4605 14895557 }
4606
4607
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
30613950 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4608 15375134 do_layer(scrollbuf, 0, screen_handles[1], offx, offy); // LAYER 1
4609 15375134 });
4610
4611
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 do_layer_primitives(scrollbuf, 1);
4612
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 particles.draw(scrollbuf, true, 1);
4613
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 _do_current_ffc_layer(scrollbuf, 1);
4614
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 draw_msgstr(1, scrollbuf);
4615
4616 // Handle layer 2 NOT being used as background layers.
4617
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
30613950 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4618 15375134 mapscr* base_scr = screen_handles[0].base_scr;
4619
2/2
✓ Branch 0 taken 127282 times.
✓ Branch 1 taken 15247852 times.
15375134 if (!XOR(base_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4620 15247852 do_layer(scrollbuf, 0, screen_handles[2], offx, offy);
4621 15375134 });
4622
4623
2/2
✓ Branch 0 taken 15111534 times.
✓ Branch 1 taken 127282 times.
15238816 if(!XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4624 {
4625
1/2
✓ Branch 0 taken 15111534 times.
✗ Branch 1 not taken.
15111534 do_layer_primitives(scrollbuf, 2);
4626
1/2
✓ Branch 0 taken 15111534 times.
✗ Branch 1 not taken.
15111534 particles.draw(scrollbuf, true, 2);
4627 15111534 }
4628
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 _do_current_ffc_layer(scrollbuf, 2);
4629
2/2
✓ Branch 0 taken 15111534 times.
✓ Branch 1 taken 127282 times.
15238816 if(!XOR(origin_scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
4630
1/2
✓ Branch 0 taken 15111534 times.
✗ Branch 1 not taken.
15111534 draw_msgstr(2, scrollbuf);
4631
4632
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 do_primitives(scrollbuf, SPLAYER_FFC_DRAW);
4633
4634
2/2
✓ Branch 0 taken 343259 times.
✓ Branch 1 taken 14895557 times.
15238816 if(get_qr(qr_LAYER12UNDERCAVE))
4635 {
4636
2/4
✓ Branch 0 taken 343259 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 343259 times.
686518 if(showhero &&
4637
3/6
✓ Branch 0 taken 343259 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 343259 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 343259 times.
✗ Branch 5 not taken.
343259 ((Hero.getAction()==climbcovertop)||(Hero.getAction()==climbcoverbottom)))
4638 {
4639 if(Hero.getAction()==climbcovertop)
4640 {
4641 cmby2=16;
4642 }
4643 else if(Hero.getAction()==climbcoverbottom)
4644 {
4645 cmby2=-16;
4646 }
4647
4648 decorations.draw2(scrollbuf,true);
4649 Hero.draw(scrollbuf);
4650 decorations.draw(scrollbuf,true);
4651 int32_t ccx = (int32_t)(Hero.getClimbCoverX());
4652 int32_t ccy = (int32_t)(Hero.getClimbCoverY());
4653
4654 overcombo(scrollbuf,ccx-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy+cmby2),MAPCSET(ccx,ccy+cmby2));
4655 putcombo(scrollbuf,ccx-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx,ccy),MAPCSET(ccx,ccy));
4656
4657 if(int32_t(Hero.getX())&15)
4658 {
4659 overcombo(scrollbuf,ccx+16-viewport.x,ccy+cmby2+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy+cmby2),MAPCSET(ccx+16,ccy+cmby2));
4660 putcombo(scrollbuf,ccx+16-viewport.x,ccy+playing_field_offset-viewport.y,MAPCOMBO(ccx+16,ccy),MAPCSET(ccx+16,ccy));
4661 }
4662 }
4663 343259 }
4664
4665
2/2
✓ Branch 0 taken 454382 times.
✓ Branch 1 taken 14784434 times.
15238816 if (get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4666 {
4667
1/2
✓ Branch 0 taken 14784434 times.
✗ Branch 1 not taken.
29705186 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4668 14920752 do_layer(scrollbuf, -2, screen_handles[0], offx, offy); // push blocks!
4669
2/2
✓ Branch 0 taken 14190196 times.
✓ Branch 1 taken 730556 times.
14920752 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
4670 {
4671 730556 do_layer(scrollbuf, -2, screen_handles[1], offx, offy); // push blocks!
4672 730556 do_layer(scrollbuf, -2, screen_handles[2], offx, offy); // push blocks!
4673 730556 }
4674 14920752 });
4675
4676
1/2
✓ Branch 0 taken 14784434 times.
✗ Branch 1 not taken.
14784434 do_primitives(scrollbuf, SPLAYER_PUSHBLOCK);
4677 14784434 }
4678
4679 // Show walkflags cheat
4680
2/4
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15238816 times.
15238816 if (show_walkflags || show_effectflags)
4681 {
4682 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4683 do_walkflags(screen_handles, offx, offy);
4684 do_effectflags(screen_handles[0].base_scr, offx, offy);
4685 });
4686
4687 do_walkflags(0, 0);
4688 }
4689
4690
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 putscrdoors(nearby_screens, scrollbuf, 0, playing_field_offset);
4691
4692 // Lens hints, doors etc.
4693
4/8
✓ Branch 0 taken 15228787 times.
✓ Branch 1 taken 10029 times.
✓ Branch 2 taken 15228787 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 15228787 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
15238816 if(lensclk || (get_debug() && zc_getkey(KEY_L)))
4694 {
4695
2/2
✓ Branch 0 taken 4153 times.
✓ Branch 1 taken 5876 times.
10029 if(get_qr(qr_OLDLENSORDER))
4696 {
4697
1/2
✓ Branch 0 taken 4153 times.
✗ Branch 1 not taken.
4153 draw_lens_under(scrollbuf, false);
4698
1/2
✓ Branch 0 taken 4153 times.
✗ Branch 1 not taken.
4153 do_primitives(scrollbuf, SPLAYER_LENS_UNDER_1);
4699 4153 }
4700
4701
1/2
✓ Branch 0 taken 10029 times.
✗ Branch 1 not taken.
10029 draw_lens_under(scrollbuf, true);
4702
1/2
✓ Branch 0 taken 10029 times.
✗ Branch 1 not taken.
10029 do_primitives(scrollbuf, SPLAYER_LENS_UNDER_2);
4703 10029 }
4704
4705 // Blit those layers onto framebuf
4706
4707
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 set_draw_screen_clip(framebuf);
4708
4709
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 blit(scrollbuf, framebuf, 0, 0, 0, 0, 256, 232);
4710
4711 // After this point, scrollbuf is no longer drawn to - so things like dosubscr have access to a "partially rendered" frame.
4712 // I think only used for COOLSCROLL==0? Seems like a silly feature...
4713
4714 // Draw the subscreen, without clipping
4715
2/2
✓ Branch 0 taken 8962659 times.
✓ Branch 1 taken 6276157 times.
15238816 if(!get_qr(qr_SUBSCREENOVERSPRITES))
4716 {
4717 8962659 bool dotime = false;
4718
4/6
✓ Branch 0 taken 8962659 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3124128 times.
✓ Branch 3 taken 5838531 times.
✓ Branch 4 taken 3124128 times.
✗ Branch 5 not taken.
8962659 if (replay_version_check(22)) dotime = game->should_show_time();
4719
1/2
✓ Branch 0 taken 8962659 times.
✗ Branch 1 not taken.
8962659 put_passive_subscr(framebuf, 0, 0, dotime, sspUP);
4720 8962659 }
4721
4722 // Draw some sprites onto framebuf
4723
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 set_clip_rect(framebuf,0,0,256,232);
4724
4725
2/2
✓ Branch 0 taken 93735 times.
✓ Branch 1 taken 15145081 times.
15238816 if(!(pricesdisplaybuf->clip))
4726 {
4727
1/2
✓ Branch 0 taken 93735 times.
✗ Branch 1 not taken.
93735 masked_blit(pricesdisplaybuf,framebuf,0,0,0,playing_field_offset,256,176);
4728 93735 }
4729
4730
5/6
✓ Branch 0 taken 15193190 times.
✓ Branch 1 taken 45626 times.
✓ Branch 2 taken 6328 times.
✓ Branch 3 taken 15186862 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6328 times.
15238816 if (!is_extended_height_mode() && is_in_scrolling_region() && !get_qr(qr_SUBSCREENOVERSPRITES))
4731 add_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
4732
4733
8/10
✓ Branch 0 taken 15236942 times.
✓ Branch 1 taken 1874 times.
✓ Branch 2 taken 15236942 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15202190 times.
✓ Branch 5 taken 34752 times.
✓ Branch 6 taken 15202190 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 15148750 times.
✓ Branch 9 taken 53440 times.
15238816 if(showhero && ((Hero.getAction()!=climbcovertop)&&(Hero.getAction()!=climbcoverbottom)))
4734 {
4735
1/2
✓ Branch 0 taken 15148750 times.
✗ Branch 1 not taken.
15148750 Hero.draw_under(framebuf);
4736
4737
3/4
✓ Branch 0 taken 15148750 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 132138 times.
✓ Branch 3 taken 15016612 times.
15148750 if(Hero.isSwimming())
4738 {
4739
1/2
✓ Branch 0 taken 132138 times.
✗ Branch 1 not taken.
132138 decorations.draw2(framebuf,true);
4740
1/2
✓ Branch 0 taken 132138 times.
✗ Branch 1 not taken.
132138 Hero.draw(framebuf);
4741
1/2
✓ Branch 0 taken 132138 times.
✗ Branch 1 not taken.
132138 decorations.draw(framebuf,true);
4742 132138 }
4743 15148750 }
4744
4745
2/2
✓ Branch 0 taken 25135 times.
✓ Branch 1 taken 15213681 times.
15238816 if(drawguys)
4746 {
4747
4/4
✓ Branch 0 taken 1982149 times.
✓ Branch 1 taken 13231532 times.
✓ Branch 2 taken 990826 times.
✓ Branch 3 taken 991323 times.
15213681 if(get_qr(qr_NOFLICKER) || (frame&1))
4748 {
4749 // Just clips sprites if in a repeating, smooth maze.
4750
2/2
✓ Branch 0 taken 14213144 times.
✓ Branch 1 taken 9214 times.
14222358 bool do_clip = maze_state.active && maze_state.loopy;
4751
4752
3/4
✓ Branch 0 taken 23183079 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8960721 times.
✓ Branch 3 taken 14222358 times.
23183079 for(int32_t i=0; i<Ewpns.Count(); i++)
4753 {
4754
3/4
✓ Branch 0 taken 8960721 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 197943 times.
✓ Branch 3 taken 8762778 times.
8960721 if(((weapon *)Ewpns.spr(i))->behind)
4755
2/4
✓ Branch 0 taken 197943 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 197943 times.
✗ Branch 3 not taken.
197943 Ewpns.spr(i)->draw(framebuf);
4756 8960721 }
4757
1/2
✓ Branch 0 taken 14222358 times.
✗ Branch 1 not taken.
14222358 do_primitives(framebuf, SPLAYER_EWEAP_BEHIND_DRAW);
4758
4759
3/4
✓ Branch 0 taken 18795994 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4573636 times.
✓ Branch 3 taken 14222358 times.
18795994 for(int32_t i=0; i<Lwpns.Count(); i++)
4760 {
4761
3/4
✓ Branch 0 taken 4573636 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3205 times.
✓ Branch 3 taken 4570431 times.
4573636 if(((weapon *)Lwpns.spr(i))->behind)
4762
2/4
✓ Branch 0 taken 3205 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3205 times.
✗ Branch 3 not taken.
3205 Lwpns.spr(i)->draw(framebuf);
4763 4573636 }
4764
1/2
✓ Branch 0 taken 14222358 times.
✗ Branch 1 not taken.
14222358 do_primitives(framebuf, SPLAYER_LWEAP_BEHIND_DRAW);
4765
4766
6/6
✓ Branch 0 taken 9485757 times.
✓ Branch 1 taken 4736601 times.
✓ Branch 2 taken 1348300 times.
✓ Branch 3 taken 8137457 times.
✓ Branch 4 taken 674011 times.
✓ Branch 5 taken 674289 times.
14222358 if(get_qr(qr_SHADOWS)&&(!get_qr(qr_SHADOWSFLICKER)||frame&1))
4767 {
4768
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 8807810 times.
8811468 if (do_clip)
4769
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 guys.drawshadow_smooth_maze(framebuf,get_qr(qr_TRANSSHADOWS)!=0);
4770 else
4771
1/2
✓ Branch 0 taken 8807810 times.
✗ Branch 1 not taken.
8807810 guys.drawshadow(framebuf,get_qr(qr_TRANSSHADOWS)!=0,true);
4772 8811468 }
4773
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14218700 times.
14222358 if (do_clip)
4774
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 guys.draw_smooth_maze(framebuf);
4775 else
4776
1/2
✓ Branch 0 taken 14218700 times.
✗ Branch 1 not taken.
14218700 guys.draw(framebuf,true);
4777
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14218700 times.
14222358 if (do_clip)
4778 {
4779 3658 int maze_screen = maze_state.scr->screen;
4780
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 auto [sx, sy] = translate_screen_coordinates_to_world(maze_screen);
4781
5/10
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3658 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3658 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3658 times.
✗ Branch 9 not taken.
18290 set_clip_rect(framebuf, sx - viewport.x, sy - viewport.y, sx + 256 - viewport.x, sy + 176 - viewport.y);
4782 3658 }
4783
1/2
✓ Branch 0 taken 14222358 times.
✗ Branch 1 not taken.
14222358 do_primitives(framebuf, SPLAYER_NPC_DRAW);
4784
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14218700 times.
14222358 if (do_clip)
4785
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 clear_clip_rect(framebuf);
4786
4787
1/2
✓ Branch 0 taken 14222358 times.
✗ Branch 1 not taken.
14222358 chainlinks.draw(framebuf,true);
4788
1/2
✓ Branch 0 taken 14222358 times.
✗ Branch 1 not taken.
14222358 do_primitives(framebuf, SPLAYER_CHAINLINK_DRAW);
4789 //Lwpns.draw(framebuf,true);
4790
4791
3/4
✓ Branch 0 taken 23183079 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8960721 times.
✓ Branch 3 taken 14222358 times.
23183079 for(int32_t i=0; i<Ewpns.Count(); i++)
4792 {
4793
3/4
✓ Branch 0 taken 8960721 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8762778 times.
✓ Branch 3 taken 197943 times.
8960721 if(!((weapon *)Ewpns.spr(i))->behind)
4794
2/4
✓ Branch 0 taken 8762778 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8762778 times.
✗ Branch 3 not taken.
8762778 Ewpns.spr(i)->draw(framebuf);
4795 8960721 }
4796
1/2
✓ Branch 0 taken 14222358 times.
✗ Branch 1 not taken.
14222358 do_primitives(framebuf, SPLAYER_EWEAP_FRONT_DRAW);
4797
4798
3/4
✓ Branch 0 taken 18795994 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4573636 times.
✓ Branch 3 taken 14222358 times.
18795994 for(int32_t i=0; i<Lwpns.Count(); i++)
4799 {
4800
3/4
✓ Branch 0 taken 4573636 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4570431 times.
✓ Branch 3 taken 3205 times.
4573636 if(!((weapon *)Lwpns.spr(i))->behind)
4801
2/4
✓ Branch 0 taken 4570431 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4570431 times.
✗ Branch 3 not taken.
4570431 Lwpns.spr(i)->draw(framebuf);
4802 4573636 }
4803
1/2
✓ Branch 0 taken 14222358 times.
✗ Branch 1 not taken.
14222358 do_primitives(framebuf, SPLAYER_LWEAP_FRONT_DRAW);
4804
4805
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14218700 times.
14222358 if (do_clip)
4806
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 items.draw_smooth_maze(framebuf);
4807 else
4808
1/2
✓ Branch 0 taken 14218700 times.
✗ Branch 1 not taken.
14218700 items.draw(framebuf,true);
4809
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14218700 times.
14222358 if (do_clip)
4810 {
4811 3658 int maze_screen = maze_state.scr->screen;
4812
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 auto [sx, sy] = translate_screen_coordinates_to_world(maze_screen);
4813
5/10
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3658 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3658 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3658 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3658 times.
✗ Branch 9 not taken.
18290 set_clip_rect(framebuf, sx - viewport.x, sy - viewport.y, sx + 256 - viewport.x, sy + 176 - viewport.y);
4814 3658 }
4815
1/2
✓ Branch 0 taken 14222358 times.
✗ Branch 1 not taken.
14222358 do_primitives(framebuf, SPLAYER_ITEMSPRITE_DRAW);
4816
2/2
✓ Branch 0 taken 3658 times.
✓ Branch 1 taken 14218700 times.
14222358 if (do_clip)
4817
1/2
✓ Branch 0 taken 3658 times.
✗ Branch 1 not taken.
3658 clear_clip_rect(framebuf);
4818 14222358 }
4819 else
4820 {
4821
3/4
✓ Branch 0 taken 1496695 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 505372 times.
✓ Branch 3 taken 991323 times.
1496695 for(int32_t i=0; i<Ewpns.Count(); i++)
4822 {
4823
3/4
✓ Branch 0 taken 505372 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8645 times.
✓ Branch 3 taken 496727 times.
505372 if(((weapon *)Ewpns.spr(i))->behind)
4824
2/4
✓ Branch 0 taken 8645 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8645 times.
✗ Branch 3 not taken.
8645 Ewpns.spr(i)->draw(framebuf);
4825 505372 }
4826
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 do_primitives(framebuf, SPLAYER_EWEAP_BEHIND_DRAW);
4827
4828
3/4
✓ Branch 0 taken 1222321 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 230998 times.
✓ Branch 3 taken 991323 times.
1222321 for(int32_t i=0; i<Lwpns.Count(); i++)
4829 {
4830
2/4
✓ Branch 0 taken 230998 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 230998 times.
230998 if(((weapon *)Lwpns.spr(i))->behind)
4831 Lwpns.spr(i)->draw(framebuf);
4832 230998 }
4833
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 do_primitives(framebuf, SPLAYER_LWEAP_BEHIND_DRAW);
4834
4835
3/4
✓ Branch 0 taken 228620 times.
✓ Branch 1 taken 762703 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 228620 times.
991323 if(get_qr(qr_SHADOWS)&&(!get_qr(qr_SHADOWSFLICKER)||frame&1))
4836 {
4837
1/2
✓ Branch 0 taken 228620 times.
✗ Branch 1 not taken.
228620 guys.drawshadow(framebuf,get_qr(qr_TRANSSHADOWS)!=0,true);
4838 228620 }
4839
4840
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 items.draw(framebuf,false);
4841
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 do_primitives(framebuf, SPLAYER_ITEMSPRITE_DRAW);
4842
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 chainlinks.draw(framebuf,false);
4843
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 do_primitives(framebuf, SPLAYER_CHAINLINK_DRAW);
4844 //Lwpns.draw(framebuf,false);
4845
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 guys.draw(framebuf,false);
4846
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 do_primitives(framebuf, SPLAYER_NPC_DRAW);
4847
4848
3/4
✓ Branch 0 taken 1496695 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 505372 times.
✓ Branch 3 taken 991323 times.
1496695 for(int32_t i=0; i<Ewpns.Count(); i++)
4849 {
4850
3/4
✓ Branch 0 taken 505372 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 496727 times.
✓ Branch 3 taken 8645 times.
505372 if(!((weapon *)Ewpns.spr(i))->behind)
4851 {
4852
2/4
✓ Branch 0 taken 496727 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 496727 times.
✗ Branch 3 not taken.
496727 Ewpns.spr(i)->draw(framebuf);
4853 496727 }
4854 505372 }
4855
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 do_primitives(framebuf, SPLAYER_EWEAP_FRONT_DRAW);
4856
4857
3/4
✓ Branch 0 taken 1222321 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 230998 times.
✓ Branch 3 taken 991323 times.
1222321 for(int32_t i=0; i<Lwpns.Count(); i++)
4858 {
4859
2/4
✓ Branch 0 taken 230998 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 230998 times.
✗ Branch 3 not taken.
230998 if(!((weapon *)Lwpns.spr(i))->behind)
4860 {
4861
2/4
✓ Branch 0 taken 230998 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 230998 times.
✗ Branch 3 not taken.
230998 Lwpns.spr(i)->draw(framebuf);
4862 230998 }
4863 230998 }
4864
1/2
✓ Branch 0 taken 991323 times.
✗ Branch 1 not taken.
991323 do_primitives(framebuf, SPLAYER_LWEAP_FRONT_DRAW);
4865 }
4866
4867
1/2
✓ Branch 0 taken 15213681 times.
✗ Branch 1 not taken.
15213681 guys.draw2(framebuf,true);
4868 15213681 }
4869
4870
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15238816 times.
15238816 if(mirror_portal.destdmap > -1)
4871 mirror_portal.draw(framebuf);
4872
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 portals.draw(framebuf,true);
4873
4874
8/10
✓ Branch 0 taken 15236942 times.
✓ Branch 1 taken 1874 times.
✓ Branch 2 taken 15236942 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15202190 times.
✓ Branch 5 taken 34752 times.
✓ Branch 6 taken 15202190 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 15148750 times.
✓ Branch 9 taken 53440 times.
15238816 if(showhero && ((Hero.getAction()!=climbcovertop)&& (Hero.getAction()!=climbcoverbottom)))
4875 {
4876
2/2
✓ Branch 0 taken 14700784 times.
✓ Branch 1 taken 447966 times.
15148750 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
4877 {
4878
1/2
✓ Branch 0 taken 14700784 times.
✗ Branch 1 not taken.
14700784 mblock2.draw(framebuf,-1);
4879
1/2
✓ Branch 0 taken 14700784 times.
✗ Branch 1 not taken.
14700784 do_primitives(framebuf, SPLAYER_MOVINGBLOCK);
4880 14700784 }
4881
3/4
✓ Branch 0 taken 15148750 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15016612 times.
✓ Branch 3 taken 132138 times.
15148750 if(!Hero.isSwimming())
4882 {
4883
8/12
✓ Branch 0 taken 15016612 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15016612 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14998868 times.
✓ Branch 5 taken 17744 times.
✓ Branch 6 taken 14998868 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 14998868 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1370 times.
✓ Branch 11 taken 15015242 times.
15016612 if((Hero.getZ()>0 || Hero.getFakeZ()>0) &&(!get_qr(qr_SHADOWSFLICKER)||frame&1))
4884 {
4885
2/2
✓ Branch 0 taken 17059 times.
✓ Branch 1 taken 14999553 times.
15016612 Hero.drawshadow(framebuf,get_qr(qr_TRANSSHADOWS)!=0);
4886 17059 }
4887
4888
6/8
✓ Branch 0 taken 15016612 times.
✓ Branch 1 taken 14999553 times.
✓ Branch 2 taken 15016612 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15016612 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 15003527 times.
✓ Branch 7 taken 13085 times.
17059 if(Hero.getZ() <= (zfix)zinit.jump_hero_layer_threshold)
4889 {
4890
1/2
✓ Branch 0 taken 15003527 times.
✗ Branch 1 not taken.
15003527 decorations.draw2(framebuf,true);
4891
1/2
✓ Branch 0 taken 15003527 times.
✗ Branch 1 not taken.
15003527 Hero.draw(framebuf);
4892
1/2
✓ Branch 0 taken 15003527 times.
✗ Branch 1 not taken.
15003527 decorations.draw(framebuf,true);
4893 15003527 }
4894 15016612 }
4895 15148750 }
4896
4897
3/4
✓ Branch 0 taken 53837400 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38598584 times.
✓ Branch 3 taken 15238816 times.
53837400 for(int32_t i=0; i<guys.Count(); i++)
4898 {
4899
3/4
✓ Branch 0 taken 38598584 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15661899 times.
✓ Branch 3 taken 22936685 times.
38598584 if(((enemy*)guys.spr(i))->family == eeWALK)
4900 {
4901
3/4
✓ Branch 0 taken 15661899 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7295 times.
✓ Branch 3 taken 15654604 times.
15661899 if(((eStalfos*)guys.spr(i))->hashero)
4902 {
4903
2/4
✓ Branch 0 taken 7295 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7295 times.
✗ Branch 3 not taken.
7295 guys.spr(i)->draw(framebuf);
4904 7295 }
4905 15661899 }
4906
4907
3/4
✓ Branch 0 taken 38598584 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 479557 times.
✓ Branch 3 taken 38119027 times.
38598584 if(((enemy*)guys.spr(i))->family == eeWALLM)
4908 {
4909
3/4
✓ Branch 0 taken 479557 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1329 times.
✓ Branch 3 taken 478228 times.
479557 if(((eWallM*)guys.spr(i))->hashero)
4910 {
4911
2/4
✓ Branch 0 taken 1329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1329 times.
✗ Branch 3 not taken.
1329 guys.spr(i)->draw(framebuf);
4912 1329 }
4913 479557 }
4914
4915
11/20
✓ Branch 0 taken 38598584 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 38598584 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 38598584 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 38598584 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 38598584 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 38598584 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 38598584 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 38598584 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 38598584 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 1342694 times.
✓ Branch 19 taken 37255890 times.
38598584 if(guys.spr(i)->z+guys.spr(i)->fakez > Hero.getZ()+Hero.getFakeZ())
4916 {
4917 //Jumping enemies in front of Hero.
4918
2/4
✓ Branch 0 taken 1342694 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1342694 times.
✗ Branch 3 not taken.
1342694 guys.spr(i)->draw(framebuf);
4919 1342694 }
4920
1/2
✓ Branch 0 taken 38598584 times.
✗ Branch 1 not taken.
38598584 do_primitives(framebuf, SPLAYER_NPC_ABOVEPLAYER_DRAW);
4921 38598584 }
4922
4923 // Draw some layers onto framebuf
4924
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 set_draw_screen_clip(framebuf);
4925
5/6
✓ Branch 0 taken 15193190 times.
✓ Branch 1 taken 45626 times.
✓ Branch 2 taken 6328 times.
✓ Branch 3 taken 15186862 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6328 times.
15238816 if (!is_extended_height_mode() && is_in_scrolling_region() && !get_qr(qr_SUBSCREENOVERSPRITES))
4926 add_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
4927
4928 // Handle layer 3 NOT being used as background layers.
4929
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
30613950 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4930 15375134 mapscr* base_scr = screen_handles[0].base_scr;
4931
2/2
✓ Branch 0 taken 92660 times.
✓ Branch 1 taken 15282474 times.
15375134 if (!XOR(base_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4932 15282474 do_layer(framebuf, 0, screen_handles[3], offx, offy);
4933 15375134 });
4934
4935
2/2
✓ Branch 0 taken 15146156 times.
✓ Branch 1 taken 92660 times.
15238816 if(!XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4936 {
4937
1/2
✓ Branch 0 taken 15146156 times.
✗ Branch 1 not taken.
15146156 do_layer_primitives(framebuf, 3);
4938
1/2
✓ Branch 0 taken 15146156 times.
✗ Branch 1 not taken.
15146156 particles.draw(framebuf, true, 3);
4939 15146156 }
4940
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 _do_current_ffc_layer(framebuf, 3);
4941
2/2
✓ Branch 0 taken 15146156 times.
✓ Branch 1 taken 92660 times.
15238816 if(!XOR(origin_scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
4942
1/2
✓ Branch 0 taken 15146156 times.
✗ Branch 1 not taken.
15146156 draw_msgstr(3);
4943
4944
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
30613950 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4945 15375134 do_layer(framebuf, 0, screen_handles[4], offx, offy);
4946 15375134 });
4947
4948
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 do_layer_primitives(framebuf, 4);
4949
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 particles.draw(framebuf, true, 4);
4950
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 _do_current_ffc_layer(framebuf, 4);
4951
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 draw_msgstr(4);
4952
4953
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
30613950 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
4954 15375134 do_layer(framebuf, -1, screen_handles[0], offx, offy);
4955
2/2
✓ Branch 0 taken 14111476 times.
✓ Branch 1 taken 1263658 times.
15375134 if (get_qr(qr_OVERHEAD_COMBOS_L1_L2))
4956 {
4957 1263658 do_layer(framebuf, -1, screen_handles[1], offx, offy);
4958 1263658 do_layer(framebuf, -1, screen_handles[2], offx, offy);
4959 1263658 }
4960 15375134 });
4961
4962
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 do_primitives(framebuf, SPLAYER_OVERHEAD_CMB);
4963
4964 // Draw some flying sprites onto framebuf
4965
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 clear_clip_rect(framebuf);
4966
5/6
✓ Branch 0 taken 15193190 times.
✓ Branch 1 taken 45626 times.
✓ Branch 2 taken 6328 times.
✓ Branch 3 taken 15186862 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6328 times.
15238816 if (!is_extended_height_mode() && is_in_scrolling_region() && !get_qr(qr_SUBSCREENOVERSPRITES))
4967 add_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
4968
4969 //Jumping Hero and jumping enemies are drawn on this layer.
4970
5/8
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 15238816 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15238816 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 13085 times.
✓ Branch 7 taken 15225731 times.
15238816 if(Hero.getZ() > (zfix)zinit.jump_hero_layer_threshold)
4971 {
4972
1/2
✓ Branch 0 taken 13085 times.
✗ Branch 1 not taken.
13085 decorations.draw2(framebuf,false);
4973
1/2
✓ Branch 0 taken 13085 times.
✗ Branch 1 not taken.
13085 Hero.draw(framebuf);
4974
1/2
✓ Branch 0 taken 13085 times.
✗ Branch 1 not taken.
13085 chainlinks.draw(framebuf,true);
4975
1/2
✓ Branch 0 taken 13085 times.
✗ Branch 1 not taken.
13085 do_primitives(framebuf, SPLAYER_CHAINLINK_DRAW);
4976
4977
3/4
✓ Branch 0 taken 15827 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2742 times.
✓ Branch 3 taken 13085 times.
15827 for(int32_t i=0; i<Lwpns.Count(); i++)
4978 {
4979
9/16
✓ Branch 0 taken 2742 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2742 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2742 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2742 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2742 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2742 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2742 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 239 times.
✓ Branch 15 taken 2503 times.
2742 if(Lwpns.spr(i)->z+Lwpns.spr(i)->fakez > (zfix)zinit.jump_hero_layer_threshold)
4980 {
4981
2/4
✓ Branch 0 taken 239 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 239 times.
✗ Branch 3 not taken.
239 Lwpns.spr(i)->draw(framebuf);
4982 239 }
4983 2742 }
4984
1/2
✓ Branch 0 taken 13085 times.
✗ Branch 1 not taken.
13085 do_primitives(framebuf, SPLAYER_LWEAP_ABOVE_DRAW);
4985
4986
1/2
✓ Branch 0 taken 13085 times.
✗ Branch 1 not taken.
13085 decorations.draw(framebuf,false);
4987 13085 }
4988
4989
5/6
✓ Branch 0 taken 3288982 times.
✓ Branch 1 taken 11949834 times.
✓ Branch 2 taken 43291556 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 31341722 times.
✓ Branch 5 taken 11949834 times.
46580538 if(!get_qr(qr_ENEMIESZAXIS)) for(int32_t i=0; i<guys.Count(); i++)
4990 {
4991
13/22
✓ Branch 0 taken 31341722 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 31341722 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 26567338 times.
✓ Branch 5 taken 4774384 times.
✓ Branch 6 taken 26567338 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 26567338 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 26567338 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 26567338 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 26567338 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 26567338 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 26567338 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 6568 times.
✓ Branch 21 taken 26560770 times.
31341722 if((isflier(guys.spr(i)->id)) || (guys.spr(i)->z+guys.spr(i)->fakez) > (zfix)zinit.jump_hero_layer_threshold)
4992 {
4993
2/4
✓ Branch 0 taken 4780952 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4780952 times.
✗ Branch 3 not taken.
4780952 guys.spr(i)->draw(framebuf);
4994 4780952 }
4995 43291556 }
4996 else
4997 {
4998
3/4
✓ Branch 0 taken 10545844 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7256862 times.
✓ Branch 3 taken 3288982 times.
10545844 for(int32_t i=0; i<guys.Count(); i++)
4999 {
5000
13/22
✓ Branch 0 taken 7256862 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7256862 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6081157 times.
✓ Branch 5 taken 1175705 times.
✓ Branch 6 taken 6081157 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6081157 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 6081157 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5594346 times.
✓ Branch 13 taken 486811 times.
✓ Branch 14 taken 5594346 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5594346 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 5594346 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 5594346 times.
7256862 if((isflier(guys.spr(i)->id)) || guys.spr(i)->z > 0 || guys.spr(i)->fakez > 0)
5001 {
5002
2/4
✓ Branch 0 taken 1662516 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1662516 times.
✗ Branch 3 not taken.
1662516 guys.spr(i)->draw(framebuf);
5003 1662516 }
5004 7256862 }
5005 }
5006
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 do_primitives(framebuf, SPLAYER_NPC_AIRBORNE_DRAW);
5007
5008 // Draw the Moving Fairy above layer 3
5009
3/4
✓ Branch 0 taken 18308078 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3069262 times.
✓ Branch 3 taken 15238816 times.
18308078 for(int32_t i=0; i<items.Count(); i++)
5010
6/8
✓ Branch 0 taken 3069262 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69034 times.
✓ Branch 3 taken 3000228 times.
✓ Branch 4 taken 69034 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 59320 times.
✓ Branch 7 taken 9714 times.
3128582 if(itemsbuf[items.spr(i)->id].family == itype_fairy && itemsbuf[items.spr(i)->id].misc3)
5011
2/4
✓ Branch 0 taken 59320 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59320 times.
✗ Branch 3 not taken.
59320 items.spr(i)->draw(framebuf);
5012
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 do_primitives(framebuf, SPLAYER_FAIRYITEM_DRAW);
5013
5014 // Draw some layers onto framebuf
5015
5016
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 set_draw_screen_clip(framebuf);
5017
5018
2/2
✓ Branch 0 taken 15224464 times.
✓ Branch 1 taken 14352 times.
15238816 if (lightbeam_present)
5019 {
5020 14352 color_map = &trans_table2;
5021
2/2
✓ Branch 0 taken 13114 times.
✓ Branch 1 taken 1238 times.
14352 if(get_qr(qr_LIGHTBEAM_TRANSPARENT))
5022
1/2
✓ Branch 0 taken 13114 times.
✗ Branch 1 not taken.
13114 draw_trans_sprite(framebuf, lightbeam_bmp, 0, playing_field_offset);
5023 else
5024
1/2
✓ Branch 0 taken 1238 times.
✗ Branch 1 not taken.
1238 masked_blit(lightbeam_bmp, framebuf, 0, 0, 0, playing_field_offset, 256, 176);
5025 14352 color_map = &trans_table;
5026 14352 }
5027
5028
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
30613950 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5029 15375134 do_layer(framebuf, 0, screen_handles[5], offx, offy);
5030 15375134 });
5031
5032
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 do_layer_primitives(framebuf, 5);
5033
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 particles.draw(framebuf, true, 5);
5034
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 _do_current_ffc_layer(framebuf, 5);
5035
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 draw_msgstr(5);
5036
5037
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 _do_current_ffc_layer(framebuf, -1); // 'overhead' freeform combos
5038
5039
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 do_primitives(framebuf, SPLAYER_OVERHEAD_FFC);
5040
5041
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
30613950 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5042 15375134 do_layer(framebuf, 0, screen_handles[6], offx, offy);
5043 15375134 });
5044
5045
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 do_layer_primitives(framebuf, 6);
5046
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 particles.draw(framebuf, true, 6);
5047
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 _do_current_ffc_layer(framebuf, 6);
5048
5049 15238816 bool any_dark = false;
5050
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
30613950 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5051 15375134 mapscr* base_scr = screen_handles[0].scr;
5052 15375134 any_dark |= is_dark(base_scr);
5053 15375134 });
5054
5055 // Handle low drawn darkness
5056
4/4
✓ Branch 0 taken 1257322 times.
✓ Branch 1 taken 13981494 times.
✓ Branch 2 taken 1013551 times.
✓ Branch 3 taken 243771 times.
15238816 if(get_qr(qr_NEW_DARKROOM) && any_dark)
5057 {
5058
1/2
✓ Branch 0 taken 243771 times.
✗ Branch 1 not taken.
493776 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5059 250005 mapscr* base_scr = screen_handles[0].scr;
5060 250005 calc_darkroom_combos(base_scr, offx, offy + playing_field_offset);
5061 250005 calc_darkroom_ffcs(base_scr, 0, playing_field_offset);
5062 250005 });
5063
1/2
✓ Branch 0 taken 243771 times.
✗ Branch 1 not taken.
243771 if(showhero)
5064
1/2
✓ Branch 0 taken 243771 times.
✗ Branch 1 not taken.
243771 Hero.calc_darkroom_hero(0, -playing_field_offset);
5065
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 243771 times.
493776 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
5066 250005 mapscr* base_scr = screen_handles[0].scr;
5067
2/2
✓ Branch 0 taken 245275 times.
✓ Branch 1 taken 4730 times.
250005 if (!is_dark(base_scr))
5068 {
5069 4730 offy += playing_field_offset;
5070 4730 rectfill(darkscr_bmp, offx - viewport.x, offy - viewport.y, offx - viewport.x + 256 - 1, offy - viewport.y + 176 - 1, 0);
5071 4730 rectfill(darkscr_bmp_trans, offx - viewport.x, offy - viewport.y, offx - viewport.x + 256 - 1, offy - viewport.y + 176 - 1, 0);
5072 4730 }
5073 250005 });
5074 243771 }
5075
5076 //Darkroom if under the subscreen
5077
6/6
✓ Branch 0 taken 1257322 times.
✓ Branch 1 taken 13981494 times.
✓ Branch 2 taken 823284 times.
✓ Branch 3 taken 434038 times.
✓ Branch 4 taken 231780 times.
✓ Branch 5 taken 591504 times.
15238816 if(get_qr(qr_NEW_DARKROOM) && get_qr(qr_NEWDARK_L6) && any_dark)
5078 {
5079
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 do_primitives(framebuf, SPLAYER_DARKROOM_UNDER);
5080
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 set_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
5081
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 231780 times.
231780 if(hero_scr->flags9 & fDARK_DITHER) //dither the entire bitmap
5082 {
5083 ditherblit(darkscr_bmp,darkscr_bmp,0,game->get_dither_type(),game->get_dither_arg());
5084 ditherblit(darkscr_bmp_trans,darkscr_bmp_trans,0,game->get_dither_type(),game->get_dither_arg());
5085 }
5086
5087 231780 color_map = &trans_table2;
5088
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 231636 times.
231780 if(hero_scr->flags9 & fDARK_TRANS) //draw the dark as transparent
5089 {
5090
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 draw_trans_sprite(framebuf, darkscr_bmp, 0, 0);
5091
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(get_qr(qr_NEWDARK_TRANS_STACKING))
5092
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5093 144 }
5094 else
5095 {
5096
1/2
✓ Branch 0 taken 231636 times.
✗ Branch 1 not taken.
231636 masked_blit(darkscr_bmp, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
5097
1/2
✓ Branch 0 taken 231636 times.
✗ Branch 1 not taken.
231636 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5098 }
5099 231780 color_map = &trans_table;
5100
5101
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 set_clip_rect(framebuf, 0, 0, framebuf->w, framebuf->h);
5102
1/2
✓ Branch 0 taken 231780 times.
✗ Branch 1 not taken.
231780 do_primitives(framebuf, SPLAYER_DARKROOM_OVER);
5103 231780 }
5104
5105
3/6
✓ Branch 0 taken 45626 times.
✓ Branch 1 taken 15193190 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 45626 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
15238816 if (is_extended_height_mode() && lensclk && !FFCore.system_suspend[susptLENS])
5106 {
5107 draw_lens_over();
5108 --lensclk;
5109 }
5110
5111 // Draw some text on framebuf
5112
5113
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 set_clip_rect(framebuf,0,0,256,232);
5114
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 if(!get_qr(qr_LAYER6_STRINGS_OVER_SUBSCREEN))
5115
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 draw_msgstr(6);
5116
5117 // Draw the subscreen, without clipping
5118
2/2
✓ Branch 0 taken 6276157 times.
✓ Branch 1 taken 8962659 times.
15238816 if(get_qr(qr_SUBSCREENOVERSPRITES))
5119 {
5120
2/4
✓ Branch 0 taken 6276157 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6276157 times.
✗ Branch 3 not taken.
6276157 put_passive_subscr(framebuf, 0, 0, game->should_show_time(), sspUP);
5121
5122 // Draw primitives over subscren
5123
1/2
✓ Branch 0 taken 6276157 times.
✗ Branch 1 not taken.
6276157 do_primitives(framebuf, 7); //Layer '7' appears above subscreen if quest rule is set
5124 6276157 }
5125
5126
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15238816 times.
15238816 if(get_qr(qr_LAYER6_STRINGS_OVER_SUBSCREEN))
5127 draw_msgstr(6);
5128
5129 // Handle high-drawn darkness
5130
6/6
✓ Branch 0 taken 1257322 times.
✓ Branch 1 taken 13981494 times.
✓ Branch 2 taken 434038 times.
✓ Branch 3 taken 823284 times.
✓ Branch 4 taken 11991 times.
✓ Branch 5 taken 422047 times.
15238816 if(get_qr(qr_NEW_DARKROOM) && !get_qr(qr_NEWDARK_L6) && any_dark)
5131 {
5132
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 do_primitives(framebuf, SPLAYER_DARKROOM_UNDER);
5133
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 set_clip_rect(framebuf, 0, playing_field_offset, framebuf->w, framebuf->h);
5134
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11991 times.
11991 if(hero_scr->flags9 & fDARK_DITHER) //dither the entire bitmap
5135 {
5136 ditherblit(darkscr_bmp,darkscr_bmp,0,game->get_dither_type(),game->get_dither_arg());
5137 ditherblit(darkscr_bmp_trans,darkscr_bmp_trans,0,game->get_dither_type(),game->get_dither_arg());
5138 }
5139
5140 11991 color_map = &trans_table2;
5141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11991 times.
11991 if(hero_scr->flags9 & fDARK_TRANS) //draw the dark as transparent
5142 {
5143 draw_trans_sprite(framebuf, darkscr_bmp, 0, 0);
5144 if(get_qr(qr_NEWDARK_TRANS_STACKING))
5145 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5146 }
5147 else
5148 {
5149
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 masked_blit(darkscr_bmp, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
5150
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 draw_trans_sprite(framebuf, darkscr_bmp_trans, 0, 0);
5151 }
5152 11991 color_map = &trans_table;
5153
5154
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 set_clip_rect(framebuf, 0, 0, framebuf->w, framebuf->h);
5155
1/2
✓ Branch 0 taken 11991 times.
✗ Branch 1 not taken.
11991 do_primitives(framebuf, SPLAYER_DARKROOM_OVER);
5156 11991 }
5157
5158
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 _do_current_ffc_layer(framebuf, 7);
5159
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 draw_msgstr(7);
5160
5161
1/2
✓ Branch 0 taken 15238816 times.
✗ Branch 1 not taken.
15238816 set_clip_rect(scrollbuf, 0, 0, scrollbuf->w, scrollbuf->h);
5162
3/4
✓ Branch 0 taken 14656279 times.
✓ Branch 1 taken 582537 times.
✓ Branch 2 taken 14656279 times.
✗ Branch 3 not taken.
15238816 if(runGeneric) FFCore.runGenericPassiveEngine(SCR_TIMING_POST_DRAW);
5163 75237028 }
5164
5165 // TODO: separate setting door data and drawing door
5166 26644 void put_door(mapscr* scr, BITMAP *dest, int32_t pos, int32_t side, int32_t type, bool redraw, bool even_walls)
5167 {
5168
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26644 times.
26644 if (type > 8) return;
5169
5170 26644 int32_t d=scr->door_combo_set;
5171
5172
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14722 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11922 times.
26644 switch(type)
5173 {
5174 case dt_wall:
5175 case dt_walk:
5176 if(!even_walls)
5177 break;
5178 [[fallthrough]];
5179 case dt_pass:
5180
3/4
✓ Branch 0 taken 1035 times.
✓ Branch 1 taken 10887 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1035 times.
11922 if(!get_qr(qr_REPLACEOPENDOORS) && !even_walls)
5181 1035 break;
5182 [[fallthrough]];
5183 case dt_lock:
5184 case dt_shut:
5185 case dt_boss:
5186 case dt_olck:
5187 case dt_osht:
5188 case dt_obos:
5189 case dt_bomb:
5190
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 6816 times.
✓ Branch 2 taken 6400 times.
✓ Branch 3 taken 6021 times.
✓ Branch 4 taken 6372 times.
25609 switch(side)
5191 {
5192 case up:
5193 6816 scr->data[pos] = DoorComboSets[d].doorcombo_u[type][0];
5194 6816 scr->cset[pos] = DoorComboSets[d].doorcset_u[type][0];
5195 6816 scr->sflag[pos] = 0;
5196 6816 scr->data[pos+1] = DoorComboSets[d].doorcombo_u[type][1];
5197 6816 scr->cset[pos+1] = DoorComboSets[d].doorcset_u[type][1];
5198 6816 scr->sflag[pos+1] = 0;
5199 6816 scr->data[pos+16] = DoorComboSets[d].doorcombo_u[type][2];
5200 6816 scr->cset[pos+16] = DoorComboSets[d].doorcset_u[type][2];
5201 6816 scr->sflag[pos+16] = 0;
5202 6816 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_u[type][3];
5203 6816 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_u[type][3];
5204 6816 scr->sflag[pos+16+1] = 0;
5205
5206
2/2
✓ Branch 0 taken 5092 times.
✓ Branch 1 taken 1724 times.
6816 if(redraw)
5207 {
5208 3448 putcombo(dest,(pos&15)<<4,pos&0xF0,
5209 1724 DoorComboSets[d].doorcombo_u[type][0],
5210 1724 DoorComboSets[d].doorcset_u[type][0]);
5211 3448 putcombo(dest,((pos&15)<<4)+16,pos&0xF0,
5212 1724 DoorComboSets[d].doorcombo_u[type][1],
5213 1724 DoorComboSets[d].doorcset_u[type][1]);
5214 1724 }
5215
5216 6816 break;
5217
5218 case down:
5219 6400 scr->data[pos] = DoorComboSets[d].doorcombo_d[type][0];
5220 6400 scr->cset[pos] = DoorComboSets[d].doorcset_d[type][0];
5221 6400 scr->sflag[pos] = 0;
5222 6400 scr->data[pos+1] = DoorComboSets[d].doorcombo_d[type][1];
5223 6400 scr->cset[pos+1] = DoorComboSets[d].doorcset_d[type][1];
5224 6400 scr->sflag[pos+1] = 0;
5225 6400 scr->data[pos+16] = DoorComboSets[d].doorcombo_d[type][2];
5226 6400 scr->cset[pos+16] = DoorComboSets[d].doorcset_d[type][2];
5227 6400 scr->sflag[pos+16] = 0;
5228 6400 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_d[type][3];
5229 6400 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_d[type][3];
5230 6400 scr->sflag[pos+16+1] = 0;
5231
5232
2/2
✓ Branch 0 taken 5160 times.
✓ Branch 1 taken 1240 times.
6400 if(redraw)
5233 {
5234 2480 putcombo(dest,(pos&15)<<4,(pos&0xF0)+16,
5235 1240 DoorComboSets[d].doorcombo_d[type][2],
5236 1240 DoorComboSets[d].doorcset_d[type][2]);
5237 2480 putcombo(dest,((pos&15)<<4)+16,(pos&0xF0)+16,
5238 1240 DoorComboSets[d].doorcombo_d[type][3],
5239 1240 DoorComboSets[d].doorcset_d[type][3]);
5240 1240 }
5241
5242 6400 break;
5243
5244 case left:
5245 6021 scr->data[pos] = DoorComboSets[d].doorcombo_l[type][0];
5246 6021 scr->cset[pos] = DoorComboSets[d].doorcset_l[type][0];
5247 6021 scr->sflag[pos] = 0;
5248 6021 scr->data[pos+1] = DoorComboSets[d].doorcombo_l[type][1];
5249 6021 scr->cset[pos+1] = DoorComboSets[d].doorcset_l[type][1];
5250 6021 scr->sflag[pos+1] = 0;
5251 6021 scr->data[pos+16] = DoorComboSets[d].doorcombo_l[type][2];
5252 6021 scr->cset[pos+16] = DoorComboSets[d].doorcset_l[type][2];
5253 6021 scr->sflag[pos+16] = 0;
5254 6021 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_l[type][3];
5255 6021 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_l[type][3];
5256 6021 scr->sflag[pos+16+1] = 0;
5257 6021 scr->data[pos+32] = DoorComboSets[d].doorcombo_l[type][4];
5258 6021 scr->cset[pos+32] = DoorComboSets[d].doorcset_l[type][4];
5259 6021 scr->sflag[pos+32] = 0;
5260 6021 scr->data[pos+32+1] = DoorComboSets[d].doorcombo_l[type][5];
5261 6021 scr->cset[pos+32+1] = DoorComboSets[d].doorcset_l[type][5];
5262 6021 scr->sflag[pos+32+1] = 0;
5263
5264
2/2
✓ Branch 0 taken 4607 times.
✓ Branch 1 taken 1414 times.
6021 if(redraw)
5265 {
5266 2828 putcombo(dest,(pos&15)<<4,pos&0xF0,
5267 1414 DoorComboSets[d].doorcombo_l[type][0],
5268 1414 DoorComboSets[d].doorcset_l[type][0]);
5269 2828 putcombo(dest,(pos&15)<<4,(pos&0xF0)+16,
5270 1414 DoorComboSets[d].doorcombo_l[type][2],
5271 1414 DoorComboSets[d].doorcset_l[type][2]);
5272 2828 putcombo(dest,(pos&15)<<4,(pos&0xF0)+32,
5273 1414 DoorComboSets[d].doorcombo_l[type][4],
5274 1414 DoorComboSets[d].doorcset_l[type][4]);
5275 1414 }
5276
5277 6021 break;
5278
5279 case right:
5280 6372 scr->data[pos] = DoorComboSets[d].doorcombo_r[type][0];
5281 6372 scr->cset[pos] = DoorComboSets[d].doorcset_r[type][0];
5282 6372 scr->sflag[pos] = 0;
5283 6372 scr->data[pos+1] = DoorComboSets[d].doorcombo_r[type][1];
5284 6372 scr->cset[pos+1] = DoorComboSets[d].doorcset_r[type][1];
5285 6372 scr->sflag[pos+1] = 0;
5286 6372 scr->data[pos+16] = DoorComboSets[d].doorcombo_r[type][2];
5287 6372 scr->cset[pos+16] = DoorComboSets[d].doorcset_r[type][2];
5288 6372 scr->sflag[pos+16] = 0;
5289 6372 scr->data[pos+16+1] = DoorComboSets[d].doorcombo_r[type][3];
5290 6372 scr->cset[pos+16+1] = DoorComboSets[d].doorcset_r[type][3];
5291 6372 scr->sflag[pos+16+1] = 0;
5292 6372 scr->data[pos+32] = DoorComboSets[d].doorcombo_r[type][4];
5293 6372 scr->cset[pos+32] = DoorComboSets[d].doorcset_r[type][4];
5294 6372 scr->sflag[pos+32] = 0;
5295 6372 scr->data[pos+32+1] = DoorComboSets[d].doorcombo_r[type][5];
5296 6372 scr->cset[pos+32+1] = DoorComboSets[d].doorcset_r[type][5];
5297 6372 scr->sflag[pos+32+1] = 0;
5298
5299
2/2
✓ Branch 0 taken 4806 times.
✓ Branch 1 taken 1566 times.
6372 if(redraw)
5300 {
5301 3132 putcombo(dest,(pos&15)<<4,pos&0xF0,
5302 1566 DoorComboSets[d].doorcombo_r[type][0],
5303 1566 DoorComboSets[d].doorcset_r[type][0]);
5304 3132 putcombo(dest,(pos&15)<<4,(pos&0xF0)+16,
5305 1566 DoorComboSets[d].doorcombo_r[type][2],
5306 1566 DoorComboSets[d].doorcset_r[type][2]);
5307 3132 putcombo(dest,(pos&15)<<4,(pos&0xF0)+32,
5308 1566 DoorComboSets[d].doorcombo_r[type][4],
5309 1566 DoorComboSets[d].doorcset_r[type][4]);
5310 1566 }
5311
5312 6372 break;
5313 }
5314
5315 25609 break;
5316
5317 default:
5318 break;
5319 }
5320 26644 }
5321
5322 678280 static void over_door(mapscr* scr, BITMAP *dest, int32_t pos, int32_t side, int32_t offx, int32_t offy)
5323 {
5324 678280 int32_t door_combo_set = scr->door_combo_set;
5325 678280 int32_t x = (pos&15)<<4;
5326 678280 int32_t y = (pos&0xF0);
5327 678280 int32_t d = door_combo_set;
5328 678280 x += offx;
5329 678280 y += offy;
5330
5331
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 154099 times.
✓ Branch 2 taken 171193 times.
✓ Branch 3 taken 187219 times.
✓ Branch 4 taken 165769 times.
678280 switch(side)
5332 {
5333 case up:
5334 308198 overcombo2(dest,x,y,
5335 154099 DoorComboSets[d].bombdoorcombo_u[0],
5336 154099 DoorComboSets[d].bombdoorcset_u[0]);
5337 308198 overcombo2(dest,x+16,y,
5338 154099 DoorComboSets[d].bombdoorcombo_u[1],
5339 154099 DoorComboSets[d].bombdoorcset_u[1]);
5340 154099 break;
5341
5342 case down:
5343 342386 overcombo2(dest,x,y,
5344 171193 DoorComboSets[d].bombdoorcombo_d[0],
5345 171193 DoorComboSets[d].bombdoorcset_d[0]);
5346 342386 overcombo2(dest,x+16,y,
5347 171193 DoorComboSets[d].bombdoorcombo_d[1],
5348 171193 DoorComboSets[d].bombdoorcset_d[1]);
5349 171193 break;
5350
5351 case left:
5352 374438 overcombo2(dest,x,y,
5353 187219 DoorComboSets[d].bombdoorcombo_l[0],
5354 187219 DoorComboSets[d].bombdoorcset_l[0]);
5355 374438 overcombo2(dest,x,y+16,
5356 187219 DoorComboSets[d].bombdoorcombo_l[1],
5357 187219 DoorComboSets[d].bombdoorcset_l[1]);
5358 374438 overcombo2(dest,x,y+16,
5359 187219 DoorComboSets[d].bombdoorcombo_l[2],
5360 187219 DoorComboSets[d].bombdoorcset_l[2]);
5361 187219 break;
5362
5363 case right:
5364 331538 overcombo2(dest,x,y,
5365 165769 DoorComboSets[d].bombdoorcombo_r[0],
5366 165769 DoorComboSets[d].bombdoorcset_r[0]);
5367 331538 overcombo2(dest,x,y+16,
5368 165769 DoorComboSets[d].bombdoorcombo_r[1],
5369 165769 DoorComboSets[d].bombdoorcset_r[1]);
5370 331538 overcombo2(dest,x,y+16,
5371 165769 DoorComboSets[d].bombdoorcombo_r[2],
5372 165769 DoorComboSets[d].bombdoorcset_r[2]);
5373 165769 break;
5374 }
5375 678280 }
5376
5377 45332 void update_door(mapscr* scr, int32_t side, int32_t door, bool even_walls)
5378 {
5379
7/8
✓ Branch 0 taken 45224 times.
✓ Branch 1 taken 108 times.
✓ Branch 2 taken 45224 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21701 times.
✓ Branch 5 taken 23523 times.
✓ Branch 6 taken 530 times.
✓ Branch 7 taken 21171 times.
45332 if(door == dNONE || (!even_walls&&(door==dWALL||door==dWALK)))
5380 24161 return;
5381
5382 int32_t doortype;
5383
5384
10/12
✓ Branch 0 taken 491 times.
✓ Branch 1 taken 596 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 11872 times.
✓ Branch 5 taken 849 times.
✓ Branch 6 taken 1454 times.
✓ Branch 7 taken 2990 times.
✓ Branch 8 taken 1597 times.
✓ Branch 9 taken 172 times.
✓ Branch 10 taken 67 times.
✓ Branch 11 taken 1083 times.
21171 switch(door)
5385 {
5386 case dWALL:
5387 doortype=dt_wall;
5388 break;
5389
5390 case dWALK:
5391 doortype=dt_walk;
5392 break;
5393
5394 case dOPEN:
5395 11872 doortype=dt_pass;
5396 11872 break;
5397
5398 case dLOCKED:
5399 849 doortype=dt_lock;
5400 849 break;
5401
5402 case dUNLOCKED:
5403 1454 doortype=dt_olck;
5404 1454 break;
5405
5406 case dSHUTTER:
5407
3/4
✓ Branch 0 taken 2638 times.
✓ Branch 1 taken 352 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2638 times.
2990 if(screenscrolling && ((HeroDir()^1)==side))
5408 {
5409 doortype=dt_osht;
5410 get_screen_state(scr->screen).open_doors = -4;
5411 break;
5412 }
5413
5414 [[fallthrough]];
5415 case d1WAYSHUTTER:
5416 3481 doortype=dt_shut;
5417 3481 break;
5418
5419 case dOPENSHUTTER:
5420 1597 doortype=dt_osht;
5421 1597 break;
5422
5423 case dBOSS:
5424 172 doortype=dt_boss;
5425 172 break;
5426
5427 case dOPENBOSS:
5428 67 doortype=dt_obos;
5429 67 break;
5430
5431 case dBOMBED:
5432 1083 doortype=dt_bomb;
5433 1083 break;
5434
5435 default:
5436 596 return;
5437 }
5438
5439
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 5286 times.
✓ Branch 2 taken 5467 times.
✓ Branch 3 taken 4844 times.
✓ Branch 4 taken 4978 times.
20575 switch(side)
5440 {
5441 case up:
5442 5286 put_door(scr,nullptr,7,side,doortype,false,even_walls);
5443 5286 break;
5444
5445 case down:
5446 5467 put_door(scr,nullptr,151,side,doortype,false,even_walls);
5447 5467 break;
5448
5449 case left:
5450 4844 put_door(scr,nullptr,64,side,doortype,false,even_walls);
5451 4844 break;
5452
5453 case right:
5454 4978 put_door(scr,nullptr,78,side,doortype,false,even_walls);
5455 4978 break;
5456 }
5457 45332 }
5458
5459 6160 void putdoor(mapscr* scr, BITMAP *dest, int32_t side, int32_t door, bool redraw, bool even_walls)
5460 {
5461 /*
5462 #define dWALL 0 // 000 0
5463 #define dBOMB 6 // 011 0
5464 #define 8 // 100 0
5465 enum {dt_pass=0, dt_lock, dt_shut, dt_boss, dt_olck, dt_osht, dt_obos, dt_wall, dt_bomb, dt_walk, dt_max};
5466 */
5467
5468
7/8
✓ Branch 0 taken 6160 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6156 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 6073 times.
✓ Branch 5 taken 83 times.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 6065 times.
6160 if(door == dNONE || (!even_walls&&(door==dWALL||door==dWALK)))
5469 91 return;
5470
5471 int32_t doortype;
5472
5473
8/12
✓ Branch 0 taken 221 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 50 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 350 times.
✓ Branch 7 taken 1439 times.
✓ Branch 8 taken 3736 times.
✓ Branch 9 taken 4 times.
✓ Branch 10 taken 51 times.
✓ Branch 11 taken 218 times.
6069 switch(door)
5474 {
5475 case dWALL:
5476 doortype=dt_wall;
5477 break;
5478
5479 case dWALK:
5480 doortype=dt_walk;
5481 break;
5482
5483 case dOPEN:
5484 50 doortype=dt_pass;
5485 50 break;
5486
5487 case dLOCKED:
5488 doortype=dt_lock;
5489 break;
5490
5491 case dUNLOCKED:
5492 350 doortype=dt_olck;
5493 350 break;
5494
5495 case dSHUTTER:
5496
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1439 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1439 if(screenscrolling && ((HeroDir()^1)==side))
5497 {
5498 doortype=dt_osht;
5499 get_screen_state(cur_screen).open_doors = -4;
5500 break;
5501 }
5502
5503 [[fallthrough]];
5504 case d1WAYSHUTTER:
5505 1660 doortype=dt_shut;
5506 1660 break;
5507
5508 case dOPENSHUTTER:
5509 3736 doortype=dt_osht;
5510 3736 break;
5511
5512 case dBOSS:
5513 4 doortype=dt_boss;
5514 4 break;
5515
5516 case dOPENBOSS:
5517 51 doortype=dt_obos;
5518 51 break;
5519
5520 case dBOMBED:
5521 218 doortype=dt_bomb;
5522 218 break;
5523
5524 default:
5525 return;
5526 }
5527
5528
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 1760 times.
✓ Branch 2 taken 1276 times.
✓ Branch 3 taken 1439 times.
✓ Branch 4 taken 1594 times.
6069 switch(side)
5529 {
5530 case up:
5531
2/2
✓ Branch 0 taken 1692 times.
✓ Branch 1 taken 68 times.
1760 switch(door)
5532 {
5533 case dBOMBED:
5534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
136 if(redraw)
5535 {
5536 68 over_door(scr,dest,39,side,0,0);
5537 68 }
5538 [[fallthrough]];
5539 default:
5540 1760 put_door(scr,dest,7,side,doortype,redraw, even_walls);
5541 1760 break;
5542 }
5543
5544 1760 break;
5545
5546 case down:
5547
2/2
✓ Branch 0 taken 1242 times.
✓ Branch 1 taken 34 times.
1276 switch(door)
5548 {
5549 case dBOMBED:
5550
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34 times.
68 if(redraw)
5551 {
5552 34 over_door(scr,dest,135,side,0,0);
5553 34 }
5554 [[fallthrough]];
5555 default:
5556 1276 put_door(scr,dest,151,side,doortype,redraw, even_walls);
5557 1276 break;
5558 }
5559
5560 1276 break;
5561
5562 case left:
5563
2/2
✓ Branch 0 taken 1389 times.
✓ Branch 1 taken 50 times.
1439 switch(door)
5564 {
5565 case dBOMBED:
5566
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
100 if(redraw)
5567 {
5568 50 over_door(scr,dest,66,side,0,0);
5569 50 }
5570 [[fallthrough]];
5571 default:
5572 1439 put_door(scr,dest,64,side,doortype,redraw, even_walls);
5573 1439 break;
5574 }
5575
5576 1439 break;
5577
5578 case right:
5579
2/2
✓ Branch 0 taken 1528 times.
✓ Branch 1 taken 66 times.
1594 switch(door)
5580 {
5581 case dBOMBED:
5582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
132 if(redraw)
5583 {
5584 66 over_door(scr,dest,77,side,0,0);
5585 66 }
5586 [[fallthrough]];
5587 default:
5588 1594 put_door(scr,dest,78,side,doortype,redraw, even_walls);
5589 1594 break;
5590 }
5591
5592 1594 break;
5593 }
5594 6160 }
5595
5596 586 void putcombo_not_zero(BITMAP *dest, int32_t x, int32_t y, int32_t combo, int32_t cset)
5597 {
5598
1/2
✓ Branch 0 taken 586 times.
✗ Branch 1 not taken.
586 if(combo!=0)
5599 {
5600 586 putcombo(dest,x, y, combo, cset);
5601 586 }
5602 586 }
5603
5604 293 void overcombo_not_zero(BITMAP *dest, int32_t x, int32_t y, int32_t combo, int32_t cset)
5605 {
5606
2/2
✓ Branch 0 taken 219 times.
✓ Branch 1 taken 74 times.
293 if(combo!=0)
5607 {
5608 219 overcombo(dest,x, y, combo, cset);
5609 219 }
5610 293 }
5611
5612 125 void showbombeddoor(mapscr* scr, BITMAP *dest, int32_t side, int32_t offx, int32_t offy)
5613 {
5614 125 int32_t d = scr->door_combo_set;
5615
5616
4/5
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
✓ Branch 2 taken 39 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 37 times.
125 switch(side)
5617 {
5618 case up:
5619 86 putcombo_not_zero(dest,((7&15)<<4) + offx,(7&0xF0) + offy,
5620 43 DoorComboSets[d].doorcombo_u[dt_bomb][0],
5621 43 DoorComboSets[d].doorcset_u[dt_bomb][0]);
5622 86 putcombo_not_zero(dest,((8&15)<<4) + offx,(8&0xF0) + offy,
5623 43 DoorComboSets[d].doorcombo_u[dt_bomb][1],
5624 43 DoorComboSets[d].doorcset_u[dt_bomb][1]);
5625 86 putcombo_not_zero(dest,((23&15)<<4) + offx,(23&0xF0) + offy,
5626 43 DoorComboSets[d].doorcombo_u[dt_bomb][2],
5627 43 DoorComboSets[d].doorcset_u[dt_bomb][2]);
5628 86 putcombo_not_zero(dest,((24&15)<<4) + offx,(24&0xF0) + offy,
5629 43 DoorComboSets[d].doorcombo_u[dt_bomb][3],
5630 43 DoorComboSets[d].doorcset_u[dt_bomb][3]);
5631 86 overcombo_not_zero(dest,((39&15)<<4) + offx,(39&0xF0) + offy,
5632 43 DoorComboSets[d].bombdoorcombo_u[0],
5633 43 DoorComboSets[d].bombdoorcset_u[0]);
5634 86 overcombo_not_zero(dest,((40&15)<<4) + offx,(40&0xF0) + offy,
5635 43 DoorComboSets[d].bombdoorcombo_u[1],
5636 43 DoorComboSets[d].bombdoorcset_u[1]);
5637 43 break;
5638
5639 case down:
5640 78 putcombo_not_zero(dest,((151&15)<<4) + offx,(151&0xF0) + offy,
5641 39 DoorComboSets[d].doorcombo_d[dt_bomb][0],
5642 39 DoorComboSets[d].doorcset_d[dt_bomb][0]);
5643 78 putcombo_not_zero(dest,((152&15)<<4) + offx,(152&0xF0) + offy,
5644 39 DoorComboSets[d].doorcombo_d[dt_bomb][1],
5645 39 DoorComboSets[d].doorcset_d[dt_bomb][1]);
5646 78 putcombo_not_zero(dest,((167&15)<<4) + offx,(167&0xF0) + offy,
5647 39 DoorComboSets[d].doorcombo_d[dt_bomb][2],
5648 39 DoorComboSets[d].doorcset_d[dt_bomb][2]);
5649 78 putcombo_not_zero(dest,((168&15)<<4) + offx,(168&0xF0) + offy,
5650 39 DoorComboSets[d].doorcombo_d[dt_bomb][3],
5651 39 DoorComboSets[d].doorcset_d[dt_bomb][3]);
5652 78 overcombo_not_zero(dest,((135&15)<<4) + offx,(135&0xF0) + offy,
5653 39 DoorComboSets[d].bombdoorcombo_d[0],
5654 39 DoorComboSets[d].bombdoorcset_d[0]);
5655 78 overcombo_not_zero(dest,((136&15)<<4) + offx,(136&0xF0) + offy,
5656 39 DoorComboSets[d].bombdoorcombo_d[1],
5657 39 DoorComboSets[d].bombdoorcset_d[1]);
5658 39 break;
5659
5660 case left:
5661 12 putcombo_not_zero(dest,((64&15)<<4) + offx,(64&0xF0) + offy,
5662 6 DoorComboSets[d].doorcombo_l[dt_bomb][0],
5663 6 DoorComboSets[d].doorcset_l[dt_bomb][0]);
5664 12 putcombo_not_zero(dest,((65&15)<<4) + offx,(65&0xF0) + offy,
5665 6 DoorComboSets[d].doorcombo_l[dt_bomb][1],
5666 6 DoorComboSets[d].doorcset_l[dt_bomb][1]);
5667 12 putcombo_not_zero(dest,((80&15)<<4) + offx,(80&0xF0) + offy,
5668 6 DoorComboSets[d].doorcombo_l[dt_bomb][2],
5669 6 DoorComboSets[d].doorcset_l[dt_bomb][2]);
5670 12 putcombo_not_zero(dest,((81&15)<<4) + offx,(81&0xF0) + offy,
5671 6 DoorComboSets[d].doorcombo_l[dt_bomb][3],
5672 6 DoorComboSets[d].doorcset_l[dt_bomb][3]);
5673 12 putcombo_not_zero(dest,((96&15)<<4) + offx,(96&0xF0) + offy,
5674 6 DoorComboSets[d].doorcombo_l[dt_bomb][4],
5675 6 DoorComboSets[d].doorcset_l[dt_bomb][4]);
5676 12 putcombo_not_zero(dest,((97&15)<<4) + offx,(97&0xF0) + offy,
5677 6 DoorComboSets[d].doorcombo_l[dt_bomb][5],
5678 6 DoorComboSets[d].doorcset_l[dt_bomb][5]);
5679 12 overcombo_not_zero(dest,((66&15)<<4) + offx,(66&0xF0) + offy,
5680 6 DoorComboSets[d].bombdoorcombo_l[0],
5681 6 DoorComboSets[d].bombdoorcset_l[0]);
5682 12 overcombo_not_zero(dest,((82&15)<<4) + offx,(82&0xF0) + offy,
5683 6 DoorComboSets[d].bombdoorcombo_l[1],
5684 6 DoorComboSets[d].bombdoorcset_l[1]);
5685 12 overcombo_not_zero(dest,((98&15)<<4) + offx,(98&0xF0) + offy,
5686 6 DoorComboSets[d].bombdoorcombo_l[2],
5687 6 DoorComboSets[d].bombdoorcset_l[2]);
5688 6 break;
5689
5690 case right:
5691 74 putcombo_not_zero(dest,((78&15)<<4) + offx,(78&0xF0) + offy,
5692 37 DoorComboSets[d].doorcombo_r[dt_bomb][0],
5693 37 DoorComboSets[d].doorcset_r[dt_bomb][0]);
5694 74 putcombo_not_zero(dest,((79&15)<<4) + offx,(79&0xF0) + offy,
5695 37 DoorComboSets[d].doorcombo_r[dt_bomb][1],
5696 37 DoorComboSets[d].doorcset_r[dt_bomb][1]);
5697 74 putcombo_not_zero(dest,((94&15)<<4) + offx,(94&0xF0) + offy,
5698 37 DoorComboSets[d].doorcombo_r[dt_bomb][2],
5699 37 DoorComboSets[d].doorcset_r[dt_bomb][2]);
5700 74 putcombo_not_zero(dest,((95&15)<<4) + offx,(95&0xF0) + offy,
5701 37 DoorComboSets[d].doorcombo_r[dt_bomb][3],
5702 37 DoorComboSets[d].doorcset_r[dt_bomb][3]);
5703 74 putcombo_not_zero(dest,((110&15)<<4) + offx,(110&0xF0) + offy,
5704 37 DoorComboSets[d].doorcombo_r[dt_bomb][4],
5705 37 DoorComboSets[d].doorcset_r[dt_bomb][4]);
5706 74 putcombo_not_zero(dest,((111&15)<<4) + offx,(111&0xF0) + offy,
5707 37 DoorComboSets[d].doorcombo_r[dt_bomb][5],
5708 37 DoorComboSets[d].doorcset_r[dt_bomb][5]);
5709 74 overcombo_not_zero(dest,((77&15)<<4) + offx,(77&0xF0) + offy,
5710 37 DoorComboSets[d].bombdoorcombo_r[0],
5711 37 DoorComboSets[d].bombdoorcset_r[0]);
5712 74 overcombo_not_zero(dest,((93&15)<<4) + offx,(93&0xF0) + offy,
5713 37 DoorComboSets[d].bombdoorcombo_r[1],
5714 37 DoorComboSets[d].bombdoorcset_r[1]);
5715 74 overcombo_not_zero(dest,((109&15)<<4) + offx,(109&0xF0) + offy,
5716 37 DoorComboSets[d].bombdoorcombo_r[2],
5717 37 DoorComboSets[d].bombdoorcset_r[2]);
5718 37 break;
5719 }
5720 125 }
5721
5722 5256599 void openshutters(mapscr* scr)
5723 {
5724 5256599 bool opened_door = false;
5725
2/2
✓ Branch 0 taken 5256599 times.
✓ Branch 1 taken 21026396 times.
26282995 for(int32_t i=0; i<4; i++)
5726
2/2
✓ Branch 0 taken 21022660 times.
✓ Branch 1 taken 3736 times.
21030132 if(scr->door[i]==dSHUTTER)
5727 {
5728 3736 putdoor(scr, scrollbuf, i, dOPENSHUTTER);
5729 3736 scr->door[i]=dOPENSHUTTER;
5730 3736 opened_door = true;
5731 3736 }
5732
5733 5256599 auto& combo_cache = combo_caches::shutter;
5734 1987810583 for_every_combo_in_screen(create_screen_handles(scr), [&](const auto& handle) {
5735
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1980943357 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1610624 times.
1982553984 if (!combo_cache.minis[handle.data()].shutter)
5736 1982553981 return;
5737 3 auto cid = handle.data();
5738 3 auto& cmb = handle.combo();
5739
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
5740 {
5741 3 auto& trig = cmb.triggers[idx];
5742
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(trig.triggerflags[0] & combotriggerSHUTTER)
5743 {
5744 3 do_trigger_combo(handle, idx);
5745
1/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(handle.data() != cid) break;
5746 }
5747 }
5748 1982553984 });
5749
5750
2/2
✓ Branch 0 taken 5254042 times.
✓ Branch 1 taken 2557 times.
5256599 if(opened_door)
5751 2557 sfx(WAV_DOOR,128);
5752 5256599 }
5753
5754 14820050 void clear_darkroom_bitmaps()
5755 {
5756 14820050 clear_to_color(darkscr_bmp, game->get_darkscr_color());
5757 14820050 clear_to_color(darkscr_bmp_trans, game->get_darkscr_color());
5758 14820050 }
5759
5760 15728604 bool is_dark(const mapscr* scr)
5761 {
5762 15728604 bool dark = scr->flags&fDARK;
5763
2/2
✓ Branch 0 taken 3722 times.
✓ Branch 1 taken 15724882 times.
15728604 if (region_is_lit) return !dark;
5764 15724882 return dark;
5765 15728604 }
5766
5767 38798 bool scrolling_is_dark(const mapscr* scr)
5768 {
5769 38798 bool dark = scr->flags&fDARK;
5770
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 38796 times.
38798 if (scrolling_region_is_lit) return !dark;
5771 38796 return dark;
5772 38798 }
5773
5774 36094 bool is_any_dark()
5775 {
5776 36094 bool dark = false;
5777 73444 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
5778 37350 dark |= (bool)(is_dark(scr));
5779 37350 });
5780 36094 return dark;
5781 }
5782
5783 407 static mapscr prev_origin_scrs[7];
5784 407 static std::set<int> loadscr_ffc_script_ids_to_remove;
5785
5786 static void handle_screen_overlay(const std::vector<mapscr*>& screens)
5787 {
5788 mapscr* base_scr = screens[0];
5789 mapscr* previous_scr = &prev_origin_scrs[0];
5790
5791 for (int i = 0; i < 176; i++)
5792 {
5793 if (base_scr->data[i] == 0)
5794 {
5795 base_scr->data[i] = previous_scr->data[i];
5796 base_scr->sflag[i] = previous_scr->sflag[i];
5797 base_scr->cset[i] = previous_scr->cset[i];
5798 }
5799 }
5800
5801 for (int i = 0; i < 6; i++)
5802 {
5803 if (previous_scr->layermap[i] > 0 && base_scr->layermap[i] > 0)
5804 {
5805 int lm = (base_scr->layermap[i]-1)*MAPSCRS+base_scr->layerscreen[i];
5806 int fm = (previous_scr->layermap[i]-1)*MAPSCRS+previous_scr->layerscreen[i];
5807
5808 for (int j = 0; j < 176; j++)
5809 {
5810 if (TheMaps[lm].data[j] == 0)
5811 {
5812 TheMaps[lm].data[j] = TheMaps[fm].data[j];
5813 TheMaps[lm].sflag[j] = TheMaps[fm].sflag[j];
5814 TheMaps[lm].cset[j] = TheMaps[fm].cset[j];
5815 }
5816 }
5817 }
5818 }
5819
5820 for (int i = 1; i <= 6; i++)
5821 {
5822 mapscr* scr = screens[i];
5823 previous_scr = &prev_origin_scrs[i];
5824
5825 if (scr->layermap[i] > 0)
5826 {
5827 for (int y = 0; y < 11; y++)
5828 {
5829 for (int x = 0; x < 16; x++)
5830 {
5831 int c = y*16+x;
5832
5833 if (scr->data[c]==0)
5834 {
5835 scr->data[c] = previous_scr->data[c];
5836 scr->sflag[c] = previous_scr->sflag[c];
5837 scr->cset[c] = previous_scr->cset[c];
5838 }
5839 }
5840 }
5841 }
5842 }
5843 }
5844
5845 36434 static void load_a_screen_and_layers_init(int dmap, int screen, int ldir, bool screen_overlay, bool ffc_overlay)
5846 {
5847 36434 std::vector<mapscr*> screens;
5848
5849
1/2
✓ Branch 0 taken 36434 times.
✗ Branch 1 not taken.
36434 const mapscr* source = get_canonical_scr(cur_map, screen);
5850
2/4
✓ Branch 0 taken 36434 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36434 times.
✗ Branch 3 not taken.
36434 mapscr* base_scr = new mapscr(*source);
5851 36434 temporary_screens[screen*7] = base_scr;
5852
1/2
✓ Branch 0 taken 36434 times.
✗ Branch 1 not taken.
36434 screens.push_back(base_scr);
5853
5854 36434 base_scr->valid |= mVALID; // layer 0 is always valid
5855
5856
2/2
✓ Branch 0 taken 1244 times.
✓ Branch 1 taken 35190 times.
36434 if (screen == cur_screen)
5857 35190 origin_scr = base_scr;
5858
2/2
✓ Branch 0 taken 1244 times.
✓ Branch 1 taken 35190 times.
36434 if (screen == hero_screen)
5859 35190 hero_scr = prev_hero_scr = base_scr;
5860
5861
2/2
✓ Branch 0 taken 119 times.
✓ Branch 1 taken 36315 times.
36434 if (source->script > 0)
5862
1/2
✓ Branch 0 taken 119 times.
✗ Branch 1 not taken.
119 FFCore.reset_script_engine_data(ScriptType::Screen, screen);
5863
5864
2/2
✓ Branch 0 taken 36434 times.
✓ Branch 1 taken 218604 times.
255038 for (int i = 0; i < 6; i++)
5865 {
5866
2/2
✓ Branch 0 taken 169899 times.
✓ Branch 1 taken 48705 times.
218604 if(source->layermap[i]>0)
5867 {
5868
3/6
✓ Branch 0 taken 48705 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48705 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48705 times.
✗ Branch 5 not taken.
48705 mapscr* layer_scr = new mapscr(*get_canonical_scr(source->layermap[i]-1, source->layerscreen[i]));
5869 48705 layer_scr->map = cur_map;
5870 48705 layer_scr->screen = screen;
5871
1/2
✓ Branch 0 taken 48705 times.
✗ Branch 1 not taken.
48705 screens.push_back(layer_scr);
5872 48705 }
5873 else
5874 {
5875
1/2
✓ Branch 0 taken 169899 times.
✗ Branch 1 not taken.
169899 mapscr* layer_scr = new mapscr();
5876 169899 layer_scr->map = cur_map;
5877 169899 layer_scr->screen = screen;
5878
1/2
✓ Branch 0 taken 169899 times.
✗ Branch 1 not taken.
169899 screens.push_back(layer_scr);
5879 }
5880 218604 temporary_screens[screen*7+i+1] = screens[i+1];
5881 218604 }
5882
5883
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36434 times.
36434 if (screen_overlay)
5884 handle_screen_overlay(screens);
5885
5886
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 36290 times.
36434 if (ffc_overlay)
5887 {
5888 144 mapscr* previous_scr = &prev_origin_scrs[0];
5889
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 int num_ffcs = previous_scr->numFFC();
5890
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 144 times.
4752 for (int i = 0; i < num_ffcs; i++)
5891 {
5892
2/2
✓ Branch 0 taken 4334 times.
✓ Branch 1 taken 274 times.
4608 if ((previous_scr->ffcs[i].flags&ffc_carryover))
5893 {
5894
2/4
✓ Branch 0 taken 274 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 274 times.
✗ Branch 3 not taken.
274 auto& ffc = base_scr->getFFC(i) = previous_scr->ffcs[i];
5895 274 ffc.screen_spawned = screen;
5896
5897
1/2
✓ Branch 0 taken 274 times.
✗ Branch 1 not taken.
274 ffc_id_t ffc_id = get_region_screen_offset(screen)*MAXFFCS + i;
5898
1/2
✓ Branch 0 taken 274 times.
✗ Branch 1 not taken.
274 loadscr_ffc_script_ids_to_remove.erase(ffc_id);
5899
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 274 times.
274 if (previous_scr->ffcs[i].flags&ffc_scriptreset)
5900 {
5901 FFCore.reset_script_engine_data(ScriptType::FFC, ffc_id);
5902 }
5903 274 }
5904 4608 }
5905 144 }
5906
5907
1/2
✓ Branch 0 taken 36434 times.
✗ Branch 1 not taken.
1120803 auto [offx, offy] = translate_screen_coordinates_to_world(screen);
5908
1/2
✓ Branch 0 taken 36434 times.
✗ Branch 1 not taken.
36434 int num_ffcs = base_scr->numFFC();
5909
2/2
✓ Branch 0 taken 1084369 times.
✓ Branch 1 taken 36434 times.
1120803 for (word i = 0; i < num_ffcs; i++)
5910 {
5911 1084369 base_scr->ffcs[i].screen_spawned = screen;
5912
1/2
✓ Branch 0 taken 1084369 times.
✗ Branch 1 not taken.
1084369 base_scr->ffcs[i].x += offx;
5913
1/2
✓ Branch 0 taken 1084369 times.
✗ Branch 1 not taken.
1084369 base_scr->ffcs[i].y += offy;
5914 1084369 }
5915 36434 }
5916
5917 36434 static void load_a_screen_and_layers_post(int dmap, int screen, int ldir)
5918 {
5919 36434 mapscr* base_scr = get_scr(screen);
5920 36434 int mi = mapind(cur_map, screen);
5921
5922 // Apply perm secrets, if applicable.
5923
2/2
✓ Branch 0 taken 10961 times.
✓ Branch 1 taken 25473 times.
36434 if (canPermSecret(dmap, screen))
5924 {
5925
2/2
✓ Branch 0 taken 22949 times.
✓ Branch 1 taken 2524 times.
25473 if(game->maps[mi] & mSECRET) // if special stuff done before
5926 {
5927 2524 reveal_hidden_stairs(base_scr, screen, false);
5928 2524 trigger_secrets_for_screen(TriggerSource::SecretsScreenState, base_scr, false);
5929 2524 }
5930
2/2
✓ Branch 0 taken 25470 times.
✓ Branch 1 taken 3 times.
25473 if(game->maps[mi] & mLIGHTBEAM) // if special stuff done before
5931 {
5932
2/2
✓ Branch 0 taken 21 times.
✓ Branch 1 taken 3 times.
24 for (int layer = 0; layer <= 6; layer++)
5933 {
5934 21 mapscr* layer_scr = get_scr_layer(screen, layer);
5935
2/2
✓ Branch 0 taken 3696 times.
✓ Branch 1 taken 21 times.
3717 for (int pos = 0; pos < 176; pos++)
5936 {
5937 3696 newcombo const* cmb = &combobuf[layer_scr->data[pos]];
5938
2/2
✓ Branch 0 taken 3693 times.
✓ Branch 1 taken 3 times.
3696 if(cmb->type == cLIGHTTARGET)
5939 {
5940
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!(cmb->usrflags&cflag1)) //Unlit version
5941 {
5942 3 layer_scr->data[pos] += 1;
5943 3 }
5944 3 }
5945 3696 }
5946 21 }
5947 3 }
5948 25473 }
5949
5950 36434 auto screen_handles = create_screen_handles(base_scr);
5951
5952 36434 int destlvl = DMaps[dmap].level;
5953 36434 toggle_switches(game->lvlswitches[destlvl], true, screen_handles);
5954 36434 toggle_gswitches_load(screen_handles);
5955
5956 36434 bool should_check_for_state_things = (screen < 0x80);
5957
2/2
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 35527 times.
36434 if (should_check_for_state_things)
5958 {
5959
2/2
✓ Branch 0 taken 35158 times.
✓ Branch 1 taken 369 times.
35527 if (game->maps[mi]&mLOCKBLOCK)
5960 369 remove_lockblocks(screen_handles);
5961
2/2
✓ Branch 0 taken 35469 times.
✓ Branch 1 taken 58 times.
35527 if (game->maps[mi]&mBOSSLOCKBLOCK)
5962 58 remove_bosslockblocks(screen_handles);
5963
2/2
✓ Branch 0 taken 35371 times.
✓ Branch 1 taken 156 times.
35527 if (game->maps[mi]&mCHEST)
5964 156 remove_chests(screen_handles);
5965
1/2
✓ Branch 0 taken 35527 times.
✗ Branch 1 not taken.
35527 if (game->maps[mi]&mLOCKEDCHEST)
5966 remove_lockedchests(screen_handles);
5967
2/2
✓ Branch 0 taken 35516 times.
✓ Branch 1 taken 11 times.
35527 if (game->maps[mi]&mBOSSCHEST)
5968 11 remove_bosschests(screen_handles);
5969
5970 35527 clear_xdoors_mi(screen_handles, mi, true);
5971 35527 clear_xstatecombos_mi(screen_handles, mi, true);
5972 35527 }
5973
5974 // check doors
5975
2/2
✓ Branch 0 taken 25472 times.
✓ Branch 1 taken 10962 times.
36434 if (isdungeon(dmap, screen))
5976 {
5977
2/2
✓ Branch 0 taken 43848 times.
✓ Branch 1 taken 10962 times.
54810 for(int32_t i=0; i<4; i++)
5978 {
5979 43848 int32_t door=base_scr->door[i];
5980
5981
5/5
✓ Branch 0 taken 4973 times.
✓ Branch 1 taken 34843 times.
✓ Branch 2 taken 2212 times.
✓ Branch 3 taken 230 times.
✓ Branch 4 taken 1590 times.
43848 switch(door)
5982 {
5983 case d1WAYSHUTTER:
5984 case dSHUTTER:
5985
3/4
✓ Branch 0 taken 1597 times.
✓ Branch 1 taken 3376 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1597 times.
4973 if ((ldir^1)==i && screen == hero_screen)
5986 {
5987 1597 base_scr->door[i]=dOPENSHUTTER;
5988 1597 }
5989
5990 4973 get_screen_state(screen).open_doors = -4;
5991 4973 break;
5992
5993 case dLOCKED:
5994
3/4
✓ Branch 0 taken 2212 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1374 times.
✓ Branch 3 taken 838 times.
2212 if(should_check_for_state_things && game->maps[mi]&(1<<i))
5995 {
5996 1374 base_scr->door[i]=dUNLOCKED;
5997 1374 }
5998
5999 2212 break;
6000
6001 case dBOSS:
6002
3/4
✓ Branch 0 taken 230 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 62 times.
✓ Branch 3 taken 168 times.
230 if(should_check_for_state_things && game->maps[mi]&(1<<i))
6003 {
6004 62 base_scr->door[i]=dOPENBOSS;
6005 62 }
6006
6007 230 break;
6008
6009 case dBOMB:
6010
3/4
✓ Branch 0 taken 1590 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1032 times.
✓ Branch 3 taken 558 times.
1590 if(should_check_for_state_things && game->maps[mi]&(1<<i))
6011 {
6012 1032 base_scr->door[i]=dBOMBED;
6013 1032 }
6014
6015 1590 break;
6016 }
6017
6018 43848 update_door(base_scr, i, base_scr->door[i]);
6019
6020
4/4
✓ Branch 0 taken 39574 times.
✓ Branch 1 taken 4274 times.
✓ Branch 2 taken 699 times.
✓ Branch 3 taken 38875 times.
43848 if(door==dSHUTTER||door==d1WAYSHUTTER)
6021 {
6022 4973 base_scr->door[i]=door;
6023 4973 }
6024 43848 }
6025 10962 }
6026
6027
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 36297 times.
36434 if (!(base_scr->flags3 & fCYCLEONINIT))
6028 36297 return;
6029
6030
2/2
✓ Branch 0 taken 137 times.
✓ Branch 1 taken 959 times.
1096 for (int32_t j=-1; j<6; ++j) // j == -1 denotes the current screen
6031 {
6032
4/4
✓ Branch 0 taken 822 times.
✓ Branch 1 taken 137 times.
✓ Branch 2 taken 377 times.
✓ Branch 3 taken 445 times.
959 if (j<0 || base_scr->layermap[j] > 0)
6033 {
6034 514 mapscr* layer_scr = get_scr_layer(screen, j + 1);
6035
3/4
✓ Branch 0 taken 377 times.
✓ Branch 1 taken 137 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 377 times.
514 mapscr* layerscreen= (j<0 ? base_scr : layer_scr->valid ? layer_scr :
6036 &TheMaps[(base_scr->layermap[j]-1)*MAPSCRS]+base_scr->layerscreen[j]);
6037
6038
2/2
✓ Branch 0 taken 90464 times.
✓ Branch 1 taken 514 times.
90978 for(int32_t i=0; i<176; ++i)
6039 {
6040 90464 int32_t c=layerscreen->data[i];
6041
6042 // New screen flag: Cycle Combos At Screen Init
6043
5/6
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 90399 times.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 29 times.
✗ Branch 5 not taken.
90464 if(combobuf[c].nextcombo != 0 && (j<0 || get_qr(qr_CMBCYCLELAYERS)))
6044 {
6045 65 int32_t r = 0;
6046
6047
4/4
✓ Branch 0 taken 65 times.
✓ Branch 1 taken 84 times.
✓ Branch 2 taken 84 times.
✓ Branch 3 taken 65 times.
149 while(combobuf[c].can_cycle() && r++ < 10)
6048 {
6049 84 newcombo const& cmb = combobuf[c];
6050 84 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
6051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 84 times.
84 auto cid = cycle_under ? layerscreen->undercombo : cmb.nextcombo;
6052 84 layerscreen->data[i] = cid;
6053
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 69 times.
84 if(!(combobuf[c].animflags & AF_CYCLENOCSET))
6054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 69 times.
69 layerscreen->cset[i] = cycle_under ? layerscreen->undercset : cmb.nextcset;
6055 84 c = layerscreen->data[i];
6056 }
6057 65 }
6058 90464 }
6059 514 }
6060 959 }
6061 36434 }
6062
6063 // Set `cur_screen` to `screen` and load new screens into temporary memory.
6064 //
6065 // Called anytime a player moves to a new screen (either via warping, scrolling, continue, starting
6066 // the game, etc...)
6067 //
6068 // Note: for regions, only the initial screen load calls this function. Simply walking between
6069 // screens in the same region does not use this, because every screen in a region is loaded into
6070 // temporary memory up front.
6071 //
6072 // If scr >= 0x80, `hero_screen` will be saved to `home_screen` and also be loaded into
6073 // `special_warp_return_scr`.
6074 //
6075 // If origin_screen_overlay is true, the old origin_scr combos will be copied to the new origin_scr combos
6076 // on all layers (but only where the new screen has a 0 combo).
6077 //
6078 // TODO: loadscr should set curdmap, but currently callers do that.
6079 35190 void loadscr(int32_t destdmap, int32_t screen, int32_t ldir, bool origin_screen_overlay, bool no_x80_dir)
6080 {
6081 35190 zapp_reporting_set_tag("screen", screen);
6082
2/2
✓ Branch 0 taken 8685 times.
✓ Branch 1 taken 26505 times.
35190 if (destdmap != -1)
6083 8685 zapp_reporting_set_tag("dmap", destdmap);
6084
6085 35190 int32_t orig_destdmap = destdmap;
6086
2/2
✓ Branch 0 taken 8685 times.
✓ Branch 1 taken 26505 times.
35190 if (destdmap < 0) destdmap = cur_dmap;
6087
6088
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35190 times.
35190 if (replay_is_active())
6089 {
6090
1/2
✓ Branch 0 taken 35190 times.
✗ Branch 1 not taken.
35190 if (replay_get_mode() == ReplayMode::ManualTakeover)
6091 replay_stop_manual_takeover();
6092
6093
2/2
✓ Branch 0 taken 26505 times.
✓ Branch 1 taken 8685 times.
35190 if (orig_destdmap != -1)
6094 {
6095
2/2
✓ Branch 0 taken 7612 times.
✓ Branch 1 taken 1073 times.
8685 if (strlen(DMaps[orig_destdmap].name) > 0)
6096 {
6097
1/2
✓ Branch 0 taken 7612 times.
✗ Branch 1 not taken.
7612 replay_step_comment(fmt::format("dmap={} {}", orig_destdmap, DMaps[orig_destdmap].name));
6098 7612 }
6099 else
6100 {
6101
1/2
✓ Branch 0 taken 1073 times.
✗ Branch 1 not taken.
1073 replay_step_comment(fmt::format("dmap={}", orig_destdmap));
6102 }
6103 8685 }
6104 35190 replay_step_comment_loadscr(screen);
6105
6106 // Reset the rngs and frame count so that recording steps can be modified without impacting
6107 // behavior of later screens.
6108 35190 replay_sync_rng();
6109 35190 }
6110
6111
2/2
✓ Branch 0 taken 1700621 times.
✓ Branch 1 taken 35190 times.
1735811 for (auto& state : get_screen_states())
6112 1700621 state.second.triggered_secrets = false;
6113 35190 slopes.clear();
6114 35190 Hero.clear_platform_ffc();
6115 35190 timeExitAllGenscript(GENSCR_ST_CHANGE_SCREEN);
6116 35190 clear_darkroom_bitmaps();
6117 35190 msgscr = nullptr;
6118
6119
2/2
✓ Branch 0 taken 50224303 times.
✓ Branch 1 taken 35190 times.
50259493 for (word x=0; x<animated_combos; x++)
6120 {
6121
2/2
✓ Branch 0 taken 20919304 times.
✓ Branch 1 taken 29304999 times.
50224303 if(combobuf[animated_combo_table4[x][0]].nextcombo!=0)
6122 {
6123 20919304 combobuf[animated_combo_table4[x][0]].aclk = 0;
6124 20919304 }
6125 50224303 }
6126 35190 reset_combo_animations2();
6127 35190 region_is_lit = false;
6128
6129 // Legacy features (combo and ffc overlays) may need the previous origin screens during loading
6130 // of the new ones.
6131 35190 bool origin_ffc_overlay = false;
6132
2/2
✓ Branch 0 taken 34092 times.
✓ Branch 1 taken 1098 times.
35190 if (origin_scr)
6133 {
6134
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 34090 times.
34092 if (!(origin_scr->flags5&fNOFFCARRYOVER))
6135 {
6136 34090 int c = origin_scr->numFFC();
6137
2/2
✓ Branch 0 taken 33946 times.
✓ Branch 1 taken 1019423 times.
1053369 for (int i = 0; i < c; i++)
6138 {
6139
2/2
✓ Branch 0 taken 1019279 times.
✓ Branch 1 taken 144 times.
1019423 if (origin_scr->ffcs[i].flags&ffc_carryover)
6140 {
6141 144 origin_ffc_overlay = true;
6142 144 break;
6143 }
6144 1019279 }
6145 34090 }
6146
6147
3/4
✓ Branch 0 taken 34092 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 144 times.
✓ Branch 3 taken 33948 times.
34092 if (origin_screen_overlay || origin_ffc_overlay)
6148 {
6149
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 144 times.
1152 for (int i = 0; i <= 6; i++)
6150 {
6151 1008 mapscr* prev_scr = get_scr_layer(cur_screen, i);
6152
1/2
✓ Branch 0 taken 1008 times.
✗ Branch 1 not taken.
1008 if (prev_scr)
6153 1008 prev_origin_scrs[i] = *prev_scr;
6154 else
6155 prev_origin_scrs[i] = {};
6156 1008 }
6157 144 }
6158 34092 }
6159
6160 // Based on origin_ffc_overlay, some ffc scripts don't get reset. This set starts with all of
6161 // them, but scripts that need their data to persist will be removed.
6162 35190 loadscr_ffc_script_ids_to_remove.clear();
6163
2/2
✓ Branch 0 taken 74049891 times.
✓ Branch 1 taken 35190 times.
74085081 for (auto& key : scriptEngineDatas | std::views::keys)
6164 {
6165
2/2
✓ Branch 0 taken 72947442 times.
✓ Branch 1 taken 1102449 times.
74049891 if (key.first == ScriptType::FFC)
6166 1102449 loadscr_ffc_script_ids_to_remove.insert(key.second);
6167 }
6168
6169 35190 load_region(destdmap, screen);
6170
2/2
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 34283 times.
35190 home_screen = screen >= 0x80 ? hero_screen : cur_screen;
6171 35190 hero_screen = screen;
6172
6173 35190 cpos_clear_all();
6174 35190 FFCore.destroyScriptableObjectsOfType(ScriptType::Screen);
6175 35190 FFCore.clear_combo_scripts();
6176
6177
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 35026 times.
35190 if (is_in_scrolling_region())
6178 {
6179
2/2
✓ Branch 0 taken 20992 times.
✓ Branch 1 taken 164 times.
21156 for (int screen = 0; screen < 128; screen++)
6180 {
6181
2/2
✓ Branch 0 taken 19584 times.
✓ Branch 1 taken 1408 times.
20992 if (is_in_current_region(screen))
6182 {
6183
1/2
✓ Branch 0 taken 1408 times.
✗ Branch 1 not taken.
1408 bool screen_overlay = origin_screen_overlay && screen == cur_screen;
6184
1/2
✓ Branch 0 taken 1408 times.
✗ Branch 1 not taken.
1408 bool ffc_overlay = origin_ffc_overlay && screen == cur_screen;
6185 1408 load_a_screen_and_layers_init(destdmap, screen, ldir, screen_overlay, ffc_overlay);
6186 1408 }
6187 20992 }
6188 164 }
6189 else
6190 {
6191 35026 load_a_screen_and_layers_init(destdmap, screen, ldir, origin_screen_overlay, origin_ffc_overlay);
6192 }
6193
6194 35190 prepare_current_region_handles();
6195
6196
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 35026 times.
35190 if (is_in_scrolling_region())
6197 {
6198
2/2
✓ Branch 0 taken 20992 times.
✓ Branch 1 taken 164 times.
21156 for (int screen = 0; screen < 128; screen++)
6199 {
6200
2/2
✓ Branch 0 taken 19584 times.
✓ Branch 1 taken 1408 times.
20992 if (is_in_current_region(screen))
6201 {
6202 1408 load_a_screen_and_layers_post(destdmap, screen, ldir);
6203 1408 }
6204 20992 }
6205 164 }
6206 else
6207 {
6208 35026 load_a_screen_and_layers_post(destdmap, screen, ldir);
6209 }
6210
6211 // If on a special screen, load the screen the player is currently on (home_screen) into special_warp_return_scr.
6212
2/2
✓ Branch 0 taken 34283 times.
✓ Branch 1 taken 907 times.
35190 if (screen >= 0x80)
6213
2/2
✓ Branch 0 taken 476 times.
✓ Branch 1 taken 431 times.
907 loadscr_old(orig_destdmap, home_screen, no_x80_dir ? -1 : ldir, origin_screen_overlay);
6214
6215 35190 update_slope_comboposes();
6216 35190 cpos_force_update();
6217 35190 trig_trigger_groups();
6218
6219
2/2
✓ Branch 0 taken 1102175 times.
✓ Branch 1 taken 35190 times.
1137365 for (int index : loadscr_ffc_script_ids_to_remove)
6220 {
6221 1102175 FFCore.destroyScriptableObject(ScriptType::FFC, index);
6222 }
6223
6224 // "extended height mode" includes the top 56 pixels as part of the visible mapscr viewport,
6225 // allowing for regions to display 4 more rows of combos (as many as ALTTP does). This part of
6226 // screen is normally reserved for the passive subscreen, but in this mode mapscr combos are drawn below it.
6227 // It is up to the quest designer to make their subscreen be actually transparent.
6228 //
6229 // When not in "extended height mode" (otherwise 56 is 0):
6230 // - playing_field_offset: 56, but changes during earthquakes
6231 // - original_playing_field_offset: always 56
6232 //
6233 // These values are used to adjust where things are drawn on screen to account for the passive subscreen. Examples:
6234 // - yofs of sprites
6235 // - bitmap y offsets in draw_screen
6236 // - drawing offsets for putscr, do_layer
6237 // - drawing offsets for various calls to overtile16 (see bomb weapon explosion)
6238 // - lots more
6239 //
6240 // TODO: consider refactor of yofs, make yofs start as 0 by default and add playing_field_offset at draw time?
6241
2/2
✓ Branch 0 taken 142 times.
✓ Branch 1 taken 35048 times.
35190 if (is_extended_height_mode())
6242 {
6243 142 playing_field_offset = 0;
6244 142 original_playing_field_offset = 0;
6245 // A few sprites exist as globals, so we must manually reset them.
6246 142 Hero.yofs = 0;
6247 142 mblock2.yofs = 0;
6248 142 }
6249 else
6250 {
6251 35048 mblock2.yofs = Hero.yofs = playing_field_offset = 56;
6252 35048 original_playing_field_offset = 56;
6253 }
6254 35190 is_any_room_dark = is_any_dark();
6255
6256 35190 game->load_portal();
6257 35190 throwGenScriptEvent(GENSCR_EVENT_CHANGE_SCREEN);
6258
3/4
✓ Branch 0 taken 35 times.
✓ Branch 1 taken 35155 times.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
35190 if (Hero.lift_wpn && get_qr(qr_CARRYABLE_NO_ACROSS_SCREEN))
6259 {
6260 delete Hero.lift_wpn;
6261 Hero.lift_wpn = nullptr;
6262 }
6263
6264 35190 enemy_spawning_has_checked_been_here = false;
6265 35190 markBmap(-1, hero_screen);
6266 35190 Hero.maybe_begin_advanced_maze();
6267 35190 }
6268
6269 // Don't use this directly! Use `loadscr` instead.
6270 907 void loadscr_old(int32_t destdmap, int32_t screen,int32_t ldir,bool overlay)
6271 {
6272
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 int32_t destlvl = DMaps[destdmap < 0 ? cur_dmap : destdmap].level;
6273
6274 907 mapscr previous_scr = *special_warp_return_scr;
6275 907 mapscr* scr = special_warp_return_scr;
6276
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 const mapscr* source = get_canonical_scr(cur_map, screen);
6277
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 *scr = *source;
6278
6279
2/2
✓ Branch 0 taken 5442 times.
✓ Branch 1 taken 907 times.
6349 for (int i = 1; i <= 6; i++)
6280 {
6281
2/2
✓ Branch 0 taken 383 times.
✓ Branch 1 taken 5059 times.
5442 if (scr->layermap[i-1] > 0)
6282
2/4
✓ Branch 0 taken 383 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 383 times.
✗ Branch 3 not taken.
383 special_warp_return_scrs[i] = *get_canonical_scr(scr->layermap[i-1] - 1, scr->layerscreen[i-1]);
6283 else
6284 5059 special_warp_return_scrs[i] = {};
6285 5442 }
6286
6287 907 scr->valid |= mVALID; //layer 0 is always valid
6288
6289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 907 times.
907 if ( source->script > 0 )
6290 {
6291 scr->script = source->script;
6292 for ( int32_t q = 0; q < 8; q++ )
6293 {
6294 scr->screeninitd[q] = source->screeninitd[q];
6295 }
6296 FFCore.reset_script_engine_data(ScriptType::Screen, screen);
6297 }
6298 else
6299 {
6300 907 scr->script = 0;
6301 }
6302
6303
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 if(overlay)
6304 {
6305 for(int32_t c=0; c< 176; ++c)
6306 {
6307 if(scr->data[c]==0)
6308 {
6309 scr->data[c]=previous_scr.data[c];
6310 scr->sflag[c]=previous_scr.sflag[c];
6311 scr->cset[c]=previous_scr.cset[c];
6312 }
6313 }
6314
6315 for(int32_t i=0; i<6; i++)
6316 {
6317 if(previous_scr.layermap[i]>0 && scr->layermap[i]>0)
6318 {
6319 int32_t lm = (scr->layermap[i]-1)*MAPSCRS+scr->layerscreen[i];
6320 int32_t fm = (previous_scr.layermap[i]-1)*MAPSCRS+previous_scr.layerscreen[i];
6321
6322 for(int32_t c=0; c< 176; ++c)
6323 {
6324 if(TheMaps[lm].data[c]==0)
6325 {
6326 TheMaps[lm].data[c] = TheMaps[fm].data[c];
6327 TheMaps[lm].sflag[c] = TheMaps[fm].sflag[c];
6328 TheMaps[lm].cset[c] = TheMaps[fm].cset[c];
6329 }
6330 }
6331 }
6332 }
6333 }
6334
6335
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
29900 auto [offx, offy] = translate_screen_coordinates_to_world(screen);
6336
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 int c = scr->numFFC();
6337
2/2
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 28993 times.
29900 for (word i = 0; i < c; i++)
6338 {
6339 28993 scr->ffcs[i].screen_spawned = screen;
6340
1/2
✓ Branch 0 taken 28993 times.
✗ Branch 1 not taken.
28993 scr->ffcs[i].x += offx;
6341
1/2
✓ Branch 0 taken 28993 times.
✗ Branch 1 not taken.
28993 scr->ffcs[i].y += offy;
6342 28993 }
6343
6344 907 int mi = mapind(cur_map, screen);
6345
6346 // Apply perm secrets, if applicable.
6347
3/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 536 times.
✓ Branch 3 taken 371 times.
907 if(canPermSecret(destdmap,screen))
6348 {
6349
3/4
✓ Branch 0 taken 536 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 204 times.
✓ Branch 3 taken 332 times.
536 if(game->maps[mi]&mSECRET) // if special stuff done before
6350 {
6351
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 reveal_hidden_stairs(scr, screen, false);
6352
6353
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 log_trigger_secret_reason(TriggerSource::SecretsScreenState);
6354
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 get_screen_state(special_warp_return_scr->screen).triggered_secrets = true;
6355 204 bool do_replay_comment = true;
6356 204 bool from_active_screen = false;
6357
2/4
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 204 times.
✗ Branch 3 not taken.
204 trigger_secrets_for_screen_internal(create_screen_handles(special_warp_return_scr), from_active_screen, false, -1, do_replay_comment);
6358 204 }
6359
2/4
✓ Branch 0 taken 536 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 536 times.
✗ Branch 3 not taken.
536 if(game->maps[mi]&mLIGHTBEAM) // if special stuff done before
6360 {
6361 for (int layer = 0; layer <= 6; layer++)
6362 {
6363 mapscr* tscr = &special_warp_return_scrs[layer];
6364 for (int pos = 0; pos < 176; pos++)
6365 {
6366 newcombo const* cmb = &combobuf[tscr->data[pos]];
6367 if(cmb->type == cLIGHTTARGET)
6368 {
6369 if(!(cmb->usrflags&cflag1)) //Unlit version
6370 {
6371 tscr->data[pos] += 1;
6372 }
6373 }
6374 }
6375 }
6376 }
6377 536 }
6378
6379 screen_handles_t screen_handles;
6380
2/2
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 6349 times.
7256 for (int i = 0; i <= 6; i++)
6381
3/4
✓ Branch 0 taken 6349 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1289 times.
✓ Branch 3 taken 5060 times.
6349 screen_handles[i] = {scr, special_warp_return_scrs[i].is_valid() ? &special_warp_return_scrs[i] : nullptr, screen, i};
6382
6383
2/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 907 times.
✗ Branch 3 not taken.
907 toggle_switches(game->lvlswitches[destlvl], true, screen_handles);
6384
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 toggle_gswitches_load(screen_handles);
6385
6386
3/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 902 times.
907 if(game->maps[mi]&mLOCKBLOCK) // if special stuff done before
6387 {
6388
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 remove_lockblocks(screen_handles);
6389 5 }
6390
6391
3/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 906 times.
907 if(game->maps[mi]&mBOSSLOCKBLOCK) // if special stuff done before
6392 {
6393
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 remove_bosslockblocks(screen_handles);
6394 1 }
6395
6396
2/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 907 times.
907 if(game->maps[mi]&mCHEST) // if special stuff done before
6397 {
6398 remove_chests(screen_handles);
6399 }
6400
6401
2/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 907 times.
907 if(game->maps[mi]&mLOCKEDCHEST) // if special stuff done before
6402 {
6403 remove_lockedchests(screen_handles);
6404 }
6405
6406
2/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 907 times.
907 if(game->maps[mi]&mBOSSCHEST) // if special stuff done before
6407 {
6408 remove_bosschests(screen_handles);
6409 }
6410
6411
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 clear_xdoors(screen_handles, true);
6412
1/2
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
907 clear_xstatecombos(screen_handles, true);
6413
6414 // check doors
6415
3/4
✓ Branch 0 taken 907 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 371 times.
✓ Branch 3 taken 536 times.
907 if (isdungeon(destdmap, screen))
6416 {
6417
2/2
✓ Branch 0 taken 1484 times.
✓ Branch 1 taken 371 times.
1855 for(int32_t i=0; i<4; i++)
6418 {
6419 1484 int32_t door=scr->door[i];
6420
6421
4/4
✓ Branch 0 taken 91 times.
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 89 times.
✓ Branch 3 taken 1295 times.
1484 switch(door)
6422 {
6423 case d1WAYSHUTTER:
6424 case dSHUTTER:
6425
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1295 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1295 if ((ldir^1)==i && screen == home_screen)
6426 {
6427 scr->door[i]=dOPENSHUTTER;
6428 }
6429
6430
2/2
✓ Branch 0 taken 105 times.
✓ Branch 1 taken 1190 times.
1295 get_screen_state(screen).open_doors = -4;
6431 105 break;
6432
6433 case dLOCKED:
6434
3/4
✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80 times.
✓ Branch 3 taken 11 times.
91 if(game->maps[mi]&(1<<i))
6435 {
6436 80 scr->door[i]=dUNLOCKED;
6437 80 }
6438
6439 91 break;
6440
6441 case dBOSS:
6442
3/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 4 times.
9 if(game->maps[mi]&(1<<i))
6443 {
6444 5 scr->door[i]=dOPENBOSS;
6445 5 }
6446
6447 9 break;
6448
6449 case dBOMB:
6450
3/4
✓ Branch 0 taken 89 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 51 times.
✓ Branch 3 taken 38 times.
89 if(game->maps[mi]&(1<<i))
6451 {
6452 51 scr->door[i]=dBOMBED;
6453 51 }
6454
6455 89 break;
6456 }
6457
6458
2/2
✓ Branch 0 taken 1484 times.
✓ Branch 1 taken 1190 times.
294 update_door(scr, i, scr->door[i]);
6459
6460
4/4
✓ Branch 0 taken 1390 times.
✓ Branch 1 taken 94 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 1379 times.
1484 if(door==dSHUTTER||door==d1WAYSHUTTER)
6461 {
6462 105 scr->door[i]=door;
6463 105 }
6464 1484 }
6465 371 }
6466
6467
2/2
✓ Branch 0 taken 6915 times.
✓ Branch 1 taken 625 times.
7256 for(int32_t j=-1; j<6; ++j) // j == -1 denotes the current screen
6468 {
6469
4/4
✓ Branch 0 taken 5442 times.
✓ Branch 1 taken 1473 times.
✓ Branch 2 taken 2763 times.
✓ Branch 3 taken 2679 times.
6915 if (j<0 || scr->layermap[j] > 0)
6470 {
6471
4/4
✓ Branch 0 taken 907 times.
✓ Branch 1 taken 383 times.
✓ Branch 2 taken 382 times.
✓ Branch 3 taken 1 times.
4236 mapscr *layerscreen= (j<0 ? scr : special_warp_return_scrs[j+1].valid ? &special_warp_return_scrs[j+1] :
6472 1 &TheMaps[(scr->layermap[j]-1)*MAPSCRS]+scr->layerscreen[j]);
6473
6474
2/2
✓ Branch 0 taken 224660 times.
✓ Branch 1 taken 3670 times.
228330 for(int32_t i=0; i<176; ++i)
6475 {
6476 224660 int32_t c=layerscreen->data[i];
6477
6478 // New screen flag: Cycle Combos At Screen Init
6479
5/8
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 224654 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 2380 times.
✓ Branch 7 taken 2380 times.
224660 if(combobuf[c].nextcombo != 0 && (scr->flags3 & fCYCLEONINIT) && (j<0 || get_qr(qr_CMBCYCLELAYERS)))
6480 {
6481 2380 int32_t r = 0;
6482
6483
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2380 while(combobuf[c].can_cycle() && r++ < 10)
6484 {
6485 newcombo const& cmb = combobuf[c];
6486 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
6487 auto cid = cycle_under ? layerscreen->undercombo : cmb.nextcombo;
6488 layerscreen->data[i] = cid;
6489 if(!(combobuf[c].animflags & AF_CYCLENOCSET))
6490 layerscreen->cset[i] = cycle_under ? layerscreen->undercset : cmb.nextcset;
6491 c = layerscreen->data[i];
6492 }
6493 }
6494 227040 }
6495 3670 }
6496 6349 }
6497 5385 }
6498
6499 // Load screen (and layers). Unlike loadscr, this doesn't load to the global temporary_screens, but
6500 // instead returns an array of mapscr.
6501 // Used to draw/save the map.
6502 45680 std::array<mapscr, 7> loadscr2(int32_t screen)
6503 {
6504 45680 std::array<mapscr, 7> scrs;
6505 45680 mapscr* scr = &scrs[0];
6506
6507
2/2
✓ Branch 0 taken 64716181 times.
✓ Branch 1 taken 45680 times.
64761861 for(word x=0; x<animated_combos; x++)
6508 {
6509
2/2
✓ Branch 0 taken 31963685 times.
✓ Branch 1 taken 32752496 times.
64716181 if(combobuf[animated_combo_table4[x][0]].nextcombo!=0)
6510 {
6511 32752496 combobuf[animated_combo_table4[x][0]].aclk=0;
6512 32752496 }
6513 64716181 }
6514
6515
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 const mapscr* source = get_canonical_scr(cur_map, screen);
6516
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 if (!source->is_valid())
6517 {
6518 scrs[0].valid = 0;
6519 return scrs;
6520 }
6521
6522
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 *scr = *get_canonical_scr(cur_map, screen);
6523
2/2
✓ Branch 0 taken 274080 times.
✓ Branch 1 taken 45680 times.
319760 for (int i = 1; i <= 6; i++)
6524 {
6525
2/2
✓ Branch 0 taken 64814 times.
✓ Branch 1 taken 209266 times.
274080 if (scr->layermap[i-1] > 0)
6526
2/4
✓ Branch 0 taken 64814 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64814 times.
✗ Branch 3 not taken.
64814 scrs[i] = *get_canonical_scr(scr->layermap[i-1] - 1, scr->layerscreen[i-1]);
6527 else
6528 209266 scrs[i] = {};
6529 274080 }
6530
6531 screen_handles_t screen_handles;
6532
2/2
✓ Branch 0 taken 45680 times.
✓ Branch 1 taken 319760 times.
365440 for (int i = 0; i < 7; i++)
6533
3/4
✓ Branch 0 taken 319760 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 103790 times.
✓ Branch 3 taken 215970 times.
319760 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
6534
6535 45680 int mi = mapind(cur_map, screen);
6536
6537
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45626 times.
✓ Branch 3 taken 54 times.
45680 if(canPermSecret(-1,screen))
6538 {
6539
3/4
✓ Branch 0 taken 45626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5730 times.
✓ Branch 3 taken 39896 times.
45626 if(game->maps[mi]&mSECRET) // if special stuff done before
6540 {
6541
1/2
✓ Branch 0 taken 5730 times.
✗ Branch 1 not taken.
5730 reveal_hidden_stairs(scr, screen, false);
6542 5730 bool from_active_screen = false;
6543 5730 bool do_replay_comment = true;
6544
1/2
✓ Branch 0 taken 5730 times.
✗ Branch 1 not taken.
5730 trigger_secrets_for_screen_internal(screen_handles, from_active_screen, false, -1, do_replay_comment);
6545 5730 }
6546
3/4
✓ Branch 0 taken 45626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45609 times.
✓ Branch 3 taken 17 times.
45626 if(game->maps[mi]&mLIGHTBEAM) // if special stuff done before
6547 {
6548
2/2
✓ Branch 0 taken 119 times.
✓ Branch 1 taken 17 times.
136 for (int layer = 0; layer <= 6; layer++)
6549 {
6550 119 mapscr* tscr = &scrs[layer];
6551
2/2
✓ Branch 0 taken 20944 times.
✓ Branch 1 taken 119 times.
21063 for (int pos = 0; pos < 176; pos++)
6552 {
6553 20944 newcombo const* cmb = &combobuf[tscr->data[pos]];
6554
2/2
✓ Branch 0 taken 20927 times.
✓ Branch 1 taken 17 times.
20944 if(cmb->type == cLIGHTTARGET)
6555 {
6556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if(!(cmb->usrflags&cflag1)) //Unlit version
6557 {
6558 17 tscr->data[pos] += 1;
6559 17 }
6560 17 }
6561 20944 }
6562 119 }
6563 17 }
6564 45626 }
6565
6566
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 233 times.
✓ Branch 3 taken 45447 times.
45680 if(game->maps[mi]&mLOCKBLOCK) // if special stuff done before
6567 {
6568
1/2
✓ Branch 0 taken 233 times.
✗ Branch 1 not taken.
233 remove_lockblocks(screen_handles);
6569 233 }
6570
6571
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 45679 times.
45680 if(game->maps[mi]&mBOSSLOCKBLOCK) // if special stuff done before
6572 {
6573
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 remove_bosslockblocks(screen_handles);
6574 1 }
6575
6576
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 101 times.
✓ Branch 3 taken 45579 times.
45680 if(game->maps[mi]&mCHEST) // if special stuff done before
6577 {
6578
1/2
✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
101 remove_chests(screen_handles);
6579 101 }
6580
6581
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 45656 times.
45680 if(game->maps[mi]&mLOCKEDCHEST) // if special stuff done before
6582 {
6583
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 remove_lockedchests(screen_handles);
6584 24 }
6585
6586
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45680 times.
45680 if(game->maps[mi]&mBOSSCHEST) // if special stuff done before
6587 {
6588 remove_bosschests(screen_handles);
6589 }
6590
6591
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 clear_xdoors(screen_handles);
6592
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 clear_xstatecombos(screen_handles);
6593
6594 // check doors
6595
3/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 54 times.
✓ Branch 3 taken 45626 times.
45680 if (isdungeon(screen))
6596 {
6597
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 54 times.
270 for(int32_t i=0; i<4; i++)
6598 {
6599 216 int32_t door=scr->door[i];
6600 216 bool putit=true;
6601
6602
4/5
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 61 times.
✓ Branch 4 taken 139 times.
216 switch(door)
6603 {
6604 case d1WAYSHUTTER:
6605 case dSHUTTER:
6606 61 break;
6607
6608 case dLOCKED:
6609
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if(game->maps[mi]&(1<<i))
6610 {
6611 12 scr->door[i]=dUNLOCKED;
6612 12 }
6613
6614 12 break;
6615
6616 case dBOSS:
6617
2/4
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
4 if(game->maps[mi]&(1<<i))
6618 {
6619 scr->door[i]=dOPENBOSS;
6620 }
6621
6622 4 break;
6623
6624 case dBOMB:
6625 if(game->maps[mi]&(1<<i))
6626 {
6627 scr->door[i]=dBOMBED;
6628 }
6629
6630 break;
6631 }
6632
6633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 216 times.
216 if(putit)
6634 {
6635
1/2
✓ Branch 0 taken 216 times.
✗ Branch 1 not taken.
216 putdoor(scr, scrollbuf, i, scr->door[i], false);
6636 216 }
6637
6638
3/4
✓ Branch 0 taken 155 times.
✓ Branch 1 taken 61 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 155 times.
216 if(door==dSHUTTER||door==d1WAYSHUTTER)
6639 {
6640 61 scr->door[i]=door;
6641 61 }
6642 216 }
6643 54 }
6644
6645
2/2
✓ Branch 0 taken 319760 times.
✓ Branch 1 taken 45680 times.
365440 for(int32_t j=-1; j<6; ++j) // j == -1 denotes the current screen
6646 {
6647
4/4
✓ Branch 0 taken 274080 times.
✓ Branch 1 taken 45680 times.
✓ Branch 2 taken 64814 times.
✓ Branch 3 taken 209266 times.
319760 if (j < 0 || scr->layermap[j] > 0)
6648 {
6649
2/2
✓ Branch 0 taken 64814 times.
✓ Branch 1 taken 45680 times.
110494 mapscr *layerscreen= (j<0 ? scr
6650 64814 : &(TheMaps[(scr->layermap[j]-1)*MAPSCRS+scr->layerscreen[j]]));
6651
6652
2/2
✓ Branch 0 taken 19446944 times.
✓ Branch 1 taken 110494 times.
19557438 for(int32_t i=0; i<176; ++i)
6653 {
6654 19446944 int32_t c=layerscreen->data[i];
6655
6656 // New screen flag: Cycle Combos At Screen Init
6657
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 19446944 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
19446944 if((scr->flags3 & fCYCLEONINIT) && (j<0 || get_qr(qr_CMBCYCLELAYERS)))
6658 {
6659 int32_t r = 0;
6660
6661 while(combobuf[c].can_cycle() && r++ < 10)
6662 {
6663 newcombo const& cmb = combobuf[c];
6664 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
6665 auto cid = cycle_under ? layerscreen->undercombo : cmb.nextcombo;
6666 layerscreen->data[i] = cid;
6667 if(!(combobuf[c].animflags & AF_CYCLENOCSET))
6668 layerscreen->cset[i] = cycle_under ? layerscreen->undercset : cmb.nextcset;
6669 c = layerscreen->data[i];
6670 }
6671 }
6672 19446944 }
6673 110494 }
6674 319760 }
6675
6676 45680 return scrs;
6677
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 }
6678
6679 18665632 void putscr(mapscr* scr, BITMAP* dest, int32_t x, int32_t y)
6680 {
6681 // This is a bogus value while screenscrolling == true, but that's ok
6682 // because it is only used to calculate the rpos, and during screenscrolling
6683 // only the modulus to get pos (draw_cmb_pos does RPOS_TO_POS) is needed, which
6684 // is always the same no matter the value of scr.
6685 18665632 int screen = get_screen_for_world_xy(x, y);
6686
6687 18665632 x -= viewport.x;
6688 18665632 y -= viewport.y;
6689
6690
3/6
✓ Branch 0 taken 18665632 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18665632 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18665632 times.
18665632 if (!scr->is_valid()||!show_layers[0]||scr->hidelayers & 1)
6691 {
6692 rectfill(dest,x,y,x+255,y+175,0);
6693 return;
6694 }
6695
6696 37202354 bool over = XOR(scr->flags7&fLAYER2BG,DMaps[cur_dmap].flags&dmfLAYER2BG)
6697
2/2
✓ Branch 0 taken 128910 times.
✓ Branch 1 taken 18536722 times.
18665632 || XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG);
6698
6699 int start_x, end_x, start_y, end_y;
6700 18665632 get_bounds_for_draw_cmb_calls(dest, x, y, start_x, end_x, start_y, end_y);
6701
2/2
✓ Branch 0 taken 18665632 times.
✓ Branch 1 taken 198785301 times.
217450933 for (int cy = start_y; cy < end_y; cy++)
6702 {
6703
2/2
✓ Branch 0 taken 3017876610 times.
✓ Branch 1 taken 198785301 times.
3216661911 for (int cx = start_x; cx < end_x; cx++)
6704 {
6705 3017876610 int i = cx + cy*16;
6706
2/2
✓ Branch 0 taken 352734678 times.
✓ Branch 1 taken 2665141932 times.
3017876610 auto rpos = screenscrolling ? rpos_t::None : POS_TO_RPOS(i, screen);
6707 3017876610 draw_cmb_pos(dest, x + cx*16, y + cy*16, rpos, scr->data[i], scr->cset[i], 0, over, false);
6708 3017876610 }
6709 198785301 }
6710 18665632 }
6711
6712 15238816 static void putscrdoors(const nearby_screens_t& nearby_screens, BITMAP *dest, int32_t x, int32_t y)
6713 {
6714
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15238816 times.
15238816 if (!show_layers[0])
6715 {
6716 return;
6717 }
6718
6719 15238816 x -= viewport.x;
6720 15238816 y -= viewport.y;
6721
6722
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15238816 times.
30613950 for_every_nearby_screen(nearby_screens, [&](screen_handles_t screen_handles, int screen, int offx, int offy) {
6723 15375134 mapscr* scr = screen_handles[0].base_scr;
6724
1/2
✓ Branch 0 taken 15375134 times.
✗ Branch 1 not taken.
15375134 if (!scr->is_valid())
6725 return;
6726
6727
2/2
✓ Branch 0 taken 117787 times.
✓ Branch 1 taken 15257347 times.
15375134 if(scr->door[0]==dBOMBED)
6728 {
6729 117787 over_door(scr, dest, 39, up, offx+x, offy+y);
6730 117787 }
6731
6732
2/2
✓ Branch 0 taken 136777 times.
✓ Branch 1 taken 15238357 times.
15375134 if(scr->door[1]==dBOMBED)
6733 {
6734 136777 over_door(scr, dest, 135, down, offx+x, offy+y);
6735 136777 }
6736
6737
2/2
✓ Branch 0 taken 148249 times.
✓ Branch 1 taken 15226885 times.
15375134 if(scr->door[2]==dBOMBED)
6738 {
6739 148249 over_door(scr, dest, 66, left, offx+x, offy+y);
6740 148249 }
6741
6742
2/2
✓ Branch 0 taken 129466 times.
✓ Branch 1 taken 15245668 times.
15375134 if(scr->door[3]==dBOMBED)
6743 {
6744 129466 over_door(scr, dest, 77, right, offx+x, offy+y);
6745 129466 }
6746 15375134 });
6747 15238816 }
6748
6749 3290498 void putscrdoors(mapscr* scr, BITMAP *dest, int32_t x, int32_t y)
6750 {
6751
2/4
✓ Branch 0 taken 3290498 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3290498 times.
✗ Branch 3 not taken.
3290498 if (!scr->is_valid() || !show_layers[0])
6752 return;
6753
6754 3290498 x -= viewport.x;
6755 3290498 y -= viewport.y;
6756
6757
2/2
✓ Branch 0 taken 36244 times.
✓ Branch 1 taken 3254254 times.
3290498 if(scr->door[0]==dBOMBED)
6758 {
6759 36244 over_door(scr,dest,39,up,x,y);
6760 36244 }
6761
6762
2/2
✓ Branch 0 taken 34382 times.
✓ Branch 1 taken 3256116 times.
3290498 if(scr->door[1]==dBOMBED)
6763 {
6764 34382 over_door(scr,dest,135,down,x,y);
6765 34382 }
6766
6767
2/2
✓ Branch 0 taken 38920 times.
✓ Branch 1 taken 3251578 times.
3290498 if(scr->door[2]==dBOMBED)
6768 {
6769 38920 over_door(scr,dest,66,left,x,y);
6770 38920 }
6771
6772
2/2
✓ Branch 0 taken 36237 times.
✓ Branch 1 taken 3254261 times.
3290498 if(scr->door[3]==dBOMBED)
6773 {
6774 36237 over_door(scr,dest,77,right,x,y);
6775 36237 }
6776 3290498 }
6777 229470281 static inline bool onSwitch(newcombo const& cmb, zfix const& switchblockstate)
6778 {
6779
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 229470281 times.
✓ Branch 2 taken 229456552 times.
✓ Branch 3 taken 13729 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 13729 times.
229470281 return (switchblockstate < 0 || (cmb.attributes[2]>0 && (zslongToFix(cmb.attributes[2]) - zslongToFix(zc_max(cmb.attributes[3], 0))) <=switchblockstate));
6780 }
6781 55287594 bool _walkflag(zfix_round zx,zfix_round zy,int32_t cnt)
6782 {
6783 55287594 return _walkflag(zx,zy,cnt,0_zf);
6784 }
6785
6786 130630198 bool _walkflag_new(const mapscr* s0, const mapscr* s1, const mapscr* s2, zfix_round zx, zfix_round zy, zfix const& switchblockstate, bool is_temp_screens)
6787 {
6788 130630198 int x = zx.getRound(), y = zy.getRound();
6789 130630198 int pos = COMBOPOS(x % 256, y % 176);
6790 130630198 const newcombo& c = combobuf[s0->data[pos]];
6791 130630198 const newcombo& c1 = combobuf[s1->data[pos]];
6792 130630198 const newcombo& c2 = combobuf[s2->data[pos]];
6793
4/4
✓ Branch 0 taken 128732136 times.
✓ Branch 1 taken 1898062 times.
✓ Branch 2 taken 128722676 times.
✓ Branch 3 taken 9460 times.
261462684 bool dried = (((iswater_type(c.type)) || (iswater_type(c1.type)) ||
6794
4/4
✓ Branch 0 taken 101153 times.
✓ Branch 1 taken 128823811 times.
✓ Branch 2 taken 2004430 times.
✓ Branch 3 taken 4245 times.
130630198 (iswater_type(c2.type))) && DRIEDLAKE);
6795 130832486 int32_t b=1;
6796
2/2
✓ Branch 0 taken 64516080 times.
✓ Branch 1 taken 66316406 times.
130832486 if(x&8) b<<=2;
6797
2/2
✓ Branch 0 taken 61146143 times.
✓ Branch 1 taken 69686343 times.
130832486 if(y&8) b<<=1;
6798
6799 130832486 int32_t cwalkflag = c.walk;
6800
3/8
✓ Branch 0 taken 130731342 times.
✓ Branch 1 taken 101144 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 130731342 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
130832486 if(is_temp_screens && onSwitch(c,switchblockstate) && c.type == cCSWITCHBLOCK && c.usrflags&cflag9) cwalkflag &= (c.walk>>4)^0xF;
6801
8/10
✓ Branch 0 taken 50572 times.
✓ Branch 1 taken 130781914 times.
✓ Branch 2 taken 1999206 times.
✓ Branch 3 taken 1948634 times.
✓ Branch 4 taken 1999206 times.
✓ Branch 5 taken 130731342 times.
✓ Branch 6 taken 1999206 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1999206 times.
✗ Branch 9 not taken.
130832486 else if ((c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) || (iswater_type(c.type) && ((c.walk>>4)&b) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)))) cwalkflag = 0;
6802
2/2
✓ Branch 0 taken 61528917 times.
✓ Branch 1 taken 69202425 times.
130731342 if (s1 != s0)
6803 {
6804
2/8
✓ Branch 0 taken 69202425 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 69202425 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
69202425 if(is_temp_screens && onSwitch(c1,switchblockstate) && c1.type == cCSWITCHBLOCK && c1.usrflags&cflag9) cwalkflag &= (c1.walk>>4)^0xF;
6805
4/10
✓ Branch 0 taken 11729 times.
✓ Branch 1 taken 69190696 times.
✓ Branch 2 taken 11729 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 11729 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
69202425 else if ((iswater_type(c1.type) && ((c1.walk>>4)&b) && get_qr(qr_WATER_ON_LAYER_1) && !((c1.usrflags&cflag3) || (c1.usrflags&cflag4)))) cwalkflag &= c1.walk;
6806
2/2
✓ Branch 0 taken 62906 times.
✓ Branch 1 taken 69139519 times.
69202425 else if (c1.type == cBRIDGE)
6807 {
6808
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62906 times.
62906 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
6809 {
6810 62906 int efflag = (c1.walk & 0xF0)>>4;
6811 62906 int newsolid = (c1.walk & 0xF);
6812 62906 cwalkflag = ((newsolid | cwalkflag) & (~efflag)) | (newsolid & efflag);
6813 62906 }
6814 else cwalkflag &= c1.walk;
6815 62906 }
6816
3/8
✓ Branch 0 taken 11729 times.
✓ Branch 1 taken 69127790 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 11729 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
69139519 else if ((iswater_type(c1.type) && get_qr(qr_WATER_ON_LAYER_1) && ((c1.usrflags&cflag3) || (c1.usrflags&cflag4)) && ((c1.walk>>4)&b))) cwalkflag = 0;
6817 69139519 else cwalkflag |= c1.walk;
6818 69202425 }
6819
2/2
✓ Branch 0 taken 101194828 times.
✓ Branch 1 taken 29536514 times.
130731342 if (s2 != s0)
6820 {
6821
2/8
✓ Branch 0 taken 29536514 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 29536514 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
29536514 if(is_temp_screens && onSwitch(c2,switchblockstate) && c2.type == cCSWITCHBLOCK && c2.usrflags&cflag9) cwalkflag &= (c2.walk>>4)^0xF;
6822
4/10
✓ Branch 0 taken 2154 times.
✓ Branch 1 taken 29534360 times.
✓ Branch 2 taken 2154 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2154 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
29536514 else if ((iswater_type(c2.type) && ((c2.walk>>4)&b) && get_qr(qr_WATER_ON_LAYER_2) && !((c2.usrflags&cflag3) || (c2.usrflags&cflag4)))) cwalkflag &= c2.walk;
6823
2/2
✓ Branch 0 taken 1310 times.
✓ Branch 1 taken 29535204 times.
29536514 else if (c2.type == cBRIDGE)
6824 {
6825
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1310 times.
1310 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
6826 {
6827 1310 int efflag = (c2.walk & 0xF0)>>4;
6828 1310 int newsolid = (c2.walk & 0xF);
6829 1310 cwalkflag = ((newsolid | cwalkflag) & (~efflag)) | (newsolid & efflag);
6830 1310 }
6831 else cwalkflag &= c2.walk;
6832 1310 }
6833
3/8
✓ Branch 0 taken 2154 times.
✓ Branch 1 taken 29533050 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2154 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
29535204 else if ((iswater_type(c2.type) && get_qr(qr_WATER_ON_LAYER_2) && ((c2.usrflags&cflag3) || (c2.usrflags&cflag4))) && ((c2.walk>>4)&b)) cwalkflag = 0;
6834 29535204 else cwalkflag |= c2.walk;
6835 29536514 }
6836
6837
4/4
✓ Branch 0 taken 29066122 times.
✓ Branch 1 taken 101665220 times.
✓ Branch 2 taken 948 times.
✓ Branch 3 taken 29065174 times.
130731342 if((cwalkflag&b) && !dried)
6838 29065174 return true;
6839
6840
3/4
✓ Branch 0 taken 101666168 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 101649757 times.
✓ Branch 3 taken 16411 times.
101666168 if (is_temp_screens && collide_object(zx, zy, 0.0001_zf, 0.0001_zf)) return true;
6841
6842 101649757 return false;
6843 130731342 }
6844
6845 // Returns true if the combo at viewport position x,y is solid. Looks at a combo's quadrant walkablity flags.
6846 130731342 static bool _walkflag_new(zfix_round zx, zfix_round zy, zfix const& switchblockstate)
6847 {
6848 130731342 int x = zx.getRound(), y = zy.getRound();
6849 130731342 mapscr* s0 = get_scr_for_world_xy_layer(x, y, 0);
6850 130731342 mapscr* s1 = get_scr_for_world_xy_layer(x, y, 1);
6851 130731342 mapscr* s2 = get_scr_for_world_xy_layer(x, y, 2);
6852
2/2
✓ Branch 0 taken 61528917 times.
✓ Branch 1 taken 69202425 times.
130731342 if (!s1->valid) s1 = s0;
6853
2/2
✓ Branch 0 taken 101194828 times.
✓ Branch 1 taken 29536514 times.
130731342 if (!s2->valid) s2 = s0;
6854 130731342 return _walkflag_new(s0, s1, s2, zx, zy, switchblockstate, true);
6855 }
6856
6857 126594165 bool _walkflag(zfix_round x,zfix_round y,int32_t cnt,zfix const& switchblockstate)
6858 {
6859 126594165 int max_x = world_w;
6860 126594165 int max_y = world_h;
6861
2/2
✓ Branch 0 taken 68298207 times.
✓ Branch 1 taken 58295958 times.
126594165 if (!get_qr(qr_LTTPWALK))
6862 {
6863 58295958 max_x -= 7;
6864 58295958 max_y -= 7;
6865 58295958 }
6866
4/4
✓ Branch 0 taken 126323346 times.
✓ Branch 1 taken 270819 times.
✓ Branch 2 taken 83268 times.
✓ Branch 3 taken 126240078 times.
126594165 if (x < 0 || y < 0) return false;
6867
2/2
✓ Branch 0 taken 321050 times.
✓ Branch 1 taken 125919028 times.
126240078 if (x >= max_x) return false;
6868
3/4
✓ Branch 0 taken 537242 times.
✓ Branch 1 taken 125381786 times.
✓ Branch 2 taken 537242 times.
✗ Branch 3 not taken.
125919028 if (x >= max_x - 8 && cnt == 2) return false;
6869
2/2
✓ Branch 0 taken 125371752 times.
✓ Branch 1 taken 547276 times.
125919028 if (y >= max_y) return false;
6870
6871
4/4
✓ Branch 0 taken 28964068 times.
✓ Branch 1 taken 96407684 times.
✓ Branch 2 taken 91048094 times.
✓ Branch 3 taken 5359590 times.
125371752 return _walkflag_new(x, y, switchblockstate) || (cnt != 1 && _walkflag_new(x + 8, y, switchblockstate));
6872 126594165 }
6873
6874 97993531 static bool effectflag(int32_t x, int32_t y, int32_t layer)
6875 {
6876 97993531 mapscr* s0 = get_scr_for_world_xy(x, y);
6877 97993531 mapscr* s1 = get_scr_for_world_xy_layer(x, y, 1);
6878 97993531 mapscr* s2 = get_scr_for_world_xy_layer(x, y, 2);
6879
2/2
✓ Branch 0 taken 51358132 times.
✓ Branch 1 taken 46635399 times.
97993531 if (!s1->valid) s1 = s0;
6880
2/2
✓ Branch 0 taken 17423620 times.
✓ Branch 1 taken 80569911 times.
97993531 if (!s2->valid) s2 = s0;
6881
6882 97993531 int pos = COMBOPOS(x % 256, y % 176);
6883 97993531 const newcombo& c = combobuf[s0->data[pos]];
6884 97993531 const newcombo& c1 = combobuf[s1->data[pos]];
6885 97993531 const newcombo& c2 = combobuf[s2->data[pos]];
6886
4/4
✓ Branch 0 taken 97108896 times.
✓ Branch 1 taken 884635 times.
✓ Branch 2 taken 97107530 times.
✓ Branch 3 taken 1366 times.
195987062 bool dried = (((iswater_type(c.type)) || (iswater_type(c1.type)) ||
6887
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 97107530 times.
✓ Branch 2 taken 884165 times.
✓ Branch 3 taken 1836 times.
97993531 (iswater_type(c2.type))) && DRIEDLAKE);
6888 97993531 int32_t b=1;
6889
2/2
✓ Branch 0 taken 49305543 times.
✓ Branch 1 taken 48687988 times.
97993531 if(x&8) b<<=2;
6890
2/2
✓ Branch 0 taken 41370814 times.
✓ Branch 1 taken 56622717 times.
97993531 if(y&8) b<<=1;
6891
6892 97993531 int32_t cwalkflag = (c.walk>>4);
6893
2/2
✓ Branch 0 taken 75240784 times.
✓ Branch 1 taken 22752747 times.
97993531 if (layer == 0) cwalkflag = (c1.walk>>4);
6894
2/2
✓ Branch 0 taken 75241772 times.
✓ Branch 1 taken 22751759 times.
97993531 if (layer == 1) cwalkflag = (c2.walk>>4);
6895 //if (c.type == cBRIDGE || (iswater_type(c.type) && ((c.usrflags&cflag3) || (c.usrflags&cflag4)))) cwalkflag = 0;
6896
4/4
✓ Branch 0 taken 51358132 times.
✓ Branch 1 taken 46635399 times.
✓ Branch 2 taken 22389303 times.
✓ Branch 3 taken 28968829 times.
97993531 if (s1 != s0 && layer < 0)
6897 {
6898
2/2
✓ Branch 0 taken 22375897 times.
✓ Branch 1 taken 13406 times.
22389303 if (c1.type == cBRIDGE) cwalkflag &= (~(c1.walk>>4));
6899 22389303 }
6900
4/4
✓ Branch 0 taken 17423620 times.
✓ Branch 1 taken 80569911 times.
✓ Branch 2 taken 12903243 times.
✓ Branch 3 taken 4520377 times.
97993531 if (s2 != s0 && layer < 1)
6901 {
6902
2/2
✓ Branch 0 taken 12902891 times.
✓ Branch 1 taken 352 times.
12903243 if (c2.type == cBRIDGE) cwalkflag &= (~(c2.walk>>4));
6903 12903243 }
6904
6905
2/2
✓ Branch 0 taken 97839785 times.
✓ Branch 1 taken 153746 times.
97993531 return (cwalkflag&b) ? !dried : false;
6906 }
6907
6908 98367145 bool _effectflag(int32_t x,int32_t y,int32_t cnt, int32_t layer, bool notLink)
6909 {
6910 DCHECK(cnt == 0 || cnt == 1);
6911 98367145 int max_x = world_w;
6912 98367145 int max_y = world_h;
6913
3/4
✓ Branch 0 taken 44805237 times.
✓ Branch 1 taken 53561908 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 44805237 times.
98367145 if (!get_qr(qr_LTTPWALK) && !notLink)
6914 {
6915 44805237 max_x -= 7;
6916 44805237 max_y -= 7;
6917 44805237 }
6918
4/4
✓ Branch 0 taken 98366408 times.
✓ Branch 1 taken 737 times.
✓ Branch 2 taken 204 times.
✓ Branch 3 taken 98366204 times.
98367145 if (x < 0 || y < 0) return false;
6919
2/2
✓ Branch 0 taken 790 times.
✓ Branch 1 taken 98365414 times.
98366204 if (x >= max_x) return false;
6920
3/4
✓ Branch 0 taken 518274 times.
✓ Branch 1 taken 97847140 times.
✓ Branch 2 taken 518274 times.
✗ Branch 3 not taken.
98365414 if (x >= max_x - 8 && cnt == 2) return false;
6921
2/2
✓ Branch 0 taken 371883 times.
✓ Branch 1 taken 97993531 times.
98365414 if (y >= max_y) return false;
6922
6923
3/4
✓ Branch 0 taken 97838995 times.
✓ Branch 1 taken 154536 times.
✓ Branch 2 taken 154536 times.
✗ Branch 3 not taken.
97993531 return effectflag(x, y, layer) || (cnt == 2 && effectflag(x + 8, y, layer));
6924 98367145 }
6925
6926 // used by mapdata->isSolid(x,y) in ZScript
6927 bool _walkflag(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m)
6928 {
6929 int x = zx.getRound(), y = zy.getRound();
6930 {
6931 int max_x = 256;
6932 int max_y = 176;
6933 if (!get_qr(qr_LTTPWALK))
6934 {
6935 max_x -= 7;
6936 max_y -= 7;
6937 }
6938 if (x < 0 || y < 0) return false;
6939 if (x >= max_x) return false;
6940 if (x >= max_x - 8 && cnt == 2) return false;
6941 if (y >= max_y) return false;
6942 }
6943
6944 const mapscr *s1, *s2;
6945
6946 if ( m->layermap[0] > 0 )
6947 {
6948 s1 = get_canonical_scr(m->layermap[0], m->layerscreen[0]);
6949 }
6950 else s1 = m;
6951
6952 if ( m->layermap[1] > 0 )
6953 {
6954 s2 = get_canonical_scr(m->layermap[1], m->layerscreen[1]);
6955 }
6956 else s2 = m;
6957
6958 zfix unused;
6959 return _walkflag_new(m, s1, s2, x, y, unused, false) || (cnt != 1 && _walkflag_new(m, s1, s2, x + 8, y, unused, false));
6960 }
6961
6962 bool _walkflag_layer(zfix_round x, zfix_round y, int32_t layer, int32_t cnt)
6963 {
6964 DCHECK_LAYER_NEG1_INDEX(layer);
6965 mapscr* m = get_scr_for_world_xy_layer(x, y, layer + 1);
6966 if (!m->is_valid()) return false;
6967 return _walkflag_layer(x, y, cnt, m);
6968 }
6969
6970 static bool _walkflag_layer_new(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m, int max_x, int max_y)
6971 {
6972 int x = zx.getRound(), y = zy.getRound();
6973
6974 if (!get_qr(qr_LTTPWALK))
6975 {
6976 max_x -= 7;
6977 max_y -= 7;
6978 }
6979 if (x < 0 || y < 0) return false;
6980 if (x >= max_x) return false;
6981 if (x >= max_x - 8 && cnt == 2) return false;
6982 if (y >= max_y) return false;
6983
6984 if(!m) return true;
6985
6986 int pos = COMBOPOS(x%256, y%176);
6987 const newcombo* c = &combobuf[m->data[pos]];
6988 bool dried = ((iswater_type(c->type)) && DRIEDLAKE);
6989 int32_t b=1;
6990
6991 if(x&8) b<<=2;
6992
6993 if(y&8) b<<=1;
6994
6995 if((c->walk&b) && !dried)
6996 return true;
6997
6998 if(cnt==1) return false;
6999
7000 ++pos;
7001
7002 if(!(x&8))
7003 b<<=2;
7004 else
7005 {
7006 c = &combobuf[m->data[pos]];
7007 dried = ((iswater_type(c->type)) && DRIEDLAKE);
7008 b=1;
7009
7010 if(y&8) b<<=1;
7011 }
7012
7013 return (c->walk&b) ? !dried : false;
7014 }
7015
7016 //Only check the given mapscr*, not its layer 1&2
7017 bool _walkflag_layer(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m)
7018 {
7019 return _walkflag_layer_new(zx, zy, cnt, m, world_w, world_h);
7020 }
7021
7022 bool _walkflag_layer_scrolling(zfix_round zx,zfix_round zy,int32_t cnt, mapscr* m)
7023 {
7024 return _walkflag_layer_new(zx, zy, cnt, m, scrolling_region.width, scrolling_region.height);
7025 }
7026
7027 261239 bool _effectflag_layer(int32_t x, int32_t y, int32_t layer, int32_t cnt, bool notLink)
7028 {
7029 DCHECK_LAYER_NEG1_INDEX(layer);
7030 261239 mapscr* m = get_scr_for_world_xy_layer(x, y, layer + 1);
7031
2/2
✓ Branch 0 taken 1762 times.
✓ Branch 1 taken 259477 times.
261239 if (!m->is_valid()) return false;
7032 259477 return _effectflag_layer(x, y, cnt, m, notLink);
7033 261239 }
7034
7035 320827 bool _effectflag_layer(int32_t x,int32_t y,int32_t cnt, mapscr* m, bool notLink)
7036 {
7037 320827 int max_x = world_w;
7038 320827 int max_y = world_h;
7039
3/4
✓ Branch 0 taken 48526 times.
✓ Branch 1 taken 272301 times.
✓ Branch 2 taken 48526 times.
✗ Branch 3 not taken.
320827 if (!get_qr(qr_LTTPWALK) && !notLink)
7040 {
7041 max_x -= 7;
7042 max_y -= 7;
7043 }
7044
2/4
✓ Branch 0 taken 320827 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 320827 times.
320827 if (x < 0 || y < 0) return false;
7045
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 320827 times.
320827 if (x >= max_x) return false;
7046
3/4
✓ Branch 0 taken 1209 times.
✓ Branch 1 taken 319618 times.
✓ Branch 2 taken 1209 times.
✗ Branch 3 not taken.
320827 if (x >= max_x - 8 && cnt == 2) return false;
7047
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 320827 times.
320827 if (y >= max_y) return false;
7048
7049
1/2
✓ Branch 0 taken 320827 times.
✗ Branch 1 not taken.
320827 if (!m) return true;
7050
7051 320827 int pos = COMBOPOS(x%256, y%176);
7052 320827 const newcombo* c = &combobuf[m->data[pos]];
7053
3/4
✓ Branch 0 taken 320446 times.
✓ Branch 1 taken 381 times.
✓ Branch 2 taken 381 times.
✗ Branch 3 not taken.
321208 bool dried = ((iswater_type(c->type)) && DRIEDLAKE);
7054 320827 int32_t b=1;
7055
7056
2/2
✓ Branch 0 taken 178132 times.
✓ Branch 1 taken 142695 times.
320827 if(x&8) b<<=2;
7057
7058
2/2
✓ Branch 0 taken 135317 times.
✓ Branch 1 taken 185510 times.
320827 if(y&8) b<<=1;
7059
7060
3/4
✓ Branch 0 taken 251833 times.
✓ Branch 1 taken 68994 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 251833 times.
320827 if(((c->walk>>4)&b) && !dried)
7061 251833 return true;
7062
7063
1/2
✓ Branch 0 taken 68994 times.
✗ Branch 1 not taken.
68994 if(cnt==1) return false;
7064
7065 ++pos;
7066
7067 if(!(x&8))
7068 b<<=2;
7069 else
7070 {
7071 c = &combobuf[m->data[pos]];
7072 dried = ((iswater_type(c->type)) && DRIEDLAKE);
7073 b=1;
7074
7075 if(y&8) b<<=1;
7076 }
7077
7078 return ((c->walk>>4)&b) ? !dried : false;
7079 320827 }
7080
7081 708785 bool water_walkflag(int32_t x, int32_t y, int32_t cnt)
7082 {
7083 708785 int max_x = world_w;
7084 708785 int max_y = world_h;
7085
2/2
✓ Branch 0 taken 117367 times.
✓ Branch 1 taken 591418 times.
708785 if (!get_qr(qr_LTTPWALK))
7086 {
7087 591418 max_x -= 7;
7088 591418 max_y -= 7;
7089 591418 }
7090
2/4
✓ Branch 0 taken 708785 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 708785 times.
708785 if (x < 0 || y < 0) return false;
7091
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 708785 times.
708785 if (x >= max_x) return false;
7092
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 708785 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
708785 if (x >= max_x - 8 && cnt == 2) return false;
7093
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 708785 times.
708785 if (y >= max_y) return false;
7094
7095
3/4
✓ Branch 0 taken 15975 times.
✓ Branch 1 taken 692810 times.
✓ Branch 2 taken 692810 times.
✗ Branch 3 not taken.
708785 return water_walkflag(x, y) || (cnt != 1 && water_walkflag(x + 8, y));
7096 708785 }
7097
7098 708785 bool water_walkflag(int32_t x, int32_t y)
7099 {
7100 708785 const newcombo& c = combobuf[MAPCOMBO2(-1, x, y)];
7101 708785 const newcombo& c1 = combobuf[MAPCOMBO2(0, x, y)];
7102 708785 const newcombo& c2 = combobuf[MAPCOMBO2(1, x, y)];
7103
7104 708785 int32_t b=1;
7105
2/2
✓ Branch 0 taken 362342 times.
✓ Branch 1 taken 346443 times.
708785 if(x&8) b<<=2;
7106
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 708785 times.
708785 if(y&8) b<<=1;
7107
7108
2/2
✓ Branch 0 taken 26377 times.
✓ Branch 1 taken 682408 times.
708785 if(get_qr(qr_NO_SOLID_SWIM))
7109 {
7110
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 26245 times.
26377 if(c.walk&b)
7111 132 return true;
7112
7113
2/2
✓ Branch 0 taken 292 times.
✓ Branch 1 taken 25953 times.
26245 if(c1.walk&b)
7114 292 return true;
7115
7116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25953 times.
25953 if(c2.walk&b)
7117 return true;
7118 25953 }
7119 else
7120 {
7121
4/4
✓ Branch 0 taken 35283 times.
✓ Branch 1 taken 647125 times.
✓ Branch 2 taken 19762 times.
✓ Branch 3 taken 15521 times.
682408 if((c.walk&b) && !iswater_type(c.type))
7122 15521 return true;
7123
7124
3/4
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 666870 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
666887 if((c1.walk&b) && !iswater_type(c1.type))
7125 17 return true;
7126
7127
3/4
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 666857 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
666870 if((c2.walk&b) && !iswater_type(c2.type))
7128 13 return true;
7129 }
7130
7131 692810 return false;
7132 708785 }
7133
7134 554746 bool hit_walkflag(int32_t x,int32_t y,int32_t cnt)
7135 {
7136
2/2
✓ Branch 0 taken 90807 times.
✓ Branch 1 taken 463939 times.
554746 if(dlevel)
7137
8/8
✓ Branch 0 taken 462571 times.
✓ Branch 1 taken 1368 times.
✓ Branch 2 taken 459437 times.
✓ Branch 3 taken 3134 times.
✓ Branch 4 taken 457797 times.
✓ Branch 5 taken 1640 times.
✓ Branch 6 taken 4130 times.
✓ Branch 7 taken 453667 times.
463939 if(x<32 || y<40 || (x+(cnt-1)*8)>=world_w-32 || y>=world_h-32)
7138 10272 return true;
7139
7140
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 544472 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
544474 if(blockpath && y<((get_qr(qr_LTTPCOLLISION))?80:88))
7141 return true;
7142
7143
8/8
✓ Branch 0 taken 544205 times.
✓ Branch 1 taken 269 times.
✓ Branch 2 taken 543972 times.
✓ Branch 3 taken 233 times.
✓ Branch 4 taken 543763 times.
✓ Branch 5 taken 209 times.
✓ Branch 6 taken 346 times.
✓ Branch 7 taken 543417 times.
544474 if(x<16 || y<16 || (x+(cnt-1)*8)>=world_w-16 || y>=world_h-16)
7144 1057 return true;
7145
7146 // for(int32_t i=0; i<4; i++)
7147
4/4
✓ Branch 0 taken 841 times.
✓ Branch 1 taken 542576 times.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 805 times.
543417 if(mblock2.clk && mblock2.hit(x,y,0,cnt*8,1,16))
7148 36 return true;
7149
7150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 543381 times.
543381 if (collide_object(x, y,cnt*8, 1))
7151 return true;
7152
7153 543381 return _walkflag(x,y,cnt);
7154 554746 }
7155
7156 12110 bool solpush_walkflag(int32_t x, int32_t y, int32_t cnt, solid_object const* ign)
7157 {
7158 // 16 pixel buffer to account for slopes that are on bordering screens.
7159
4/8
✓ Branch 0 taken 12110 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12110 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12110 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 12110 times.
12110 if(x<0 || y<0 || x>=world_w+16 || y>=world_h+16)
7160 return true;
7161
7162 // for(int32_t i=0; i<4; i++)
7163
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 12110 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12110 if(mblock2.clk && mblock2.hit(x,y,0,cnt*8,1,16))
7164 return true;
7165
7166
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12110 times.
12110 if (collide_object(x, y,cnt*8, 1, ign))
7167 return true;
7168
7169 12110 return _walkflag(x,y,cnt);
7170 12110 }
7171
7172 37165 void map_bkgsfx(bool on)
7173 {
7174
2/2
✓ Branch 0 taken 37144 times.
✓ Branch 1 taken 21 times.
37165 if(on)
7175 {
7176 37144 cont_sfx(hero_scr->oceansfx);
7177
7178
4/4
✓ Branch 0 taken 368 times.
✓ Branch 1 taken 36776 times.
✓ Branch 2 taken 315 times.
✓ Branch 3 taken 53 times.
37144 if(hero_scr->bosssfx && !(game->lvlitems[dlevel]&liBOSS))
7179 315 cont_sfx(hero_scr->bosssfx);
7180 37144 }
7181 else
7182 {
7183 21 adjust_sfx(hero_scr->oceansfx,128,false);
7184 21 adjust_sfx(hero_scr->bosssfx,128,false);
7185
7186
2/2
✓ Branch 0 taken 114 times.
✓ Branch 1 taken 21 times.
135 for(int32_t i=0; i<guys.Count(); i++)
7187 {
7188
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 84 times.
114 if(((enemy*)guys.spr(i))->bgsfx)
7189 84 stop_sfx(((enemy*)guys.spr(i))->bgsfx);
7190 114 }
7191 }
7192 37165 }
7193
7194 239 void toggle_switches(dword flags, bool entry)
7195 {
7196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 239 times.
239 if(!flags) return; //No flags to toggle
7197
7198 478 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
7199 239 toggle_switches(flags, entry, create_screen_handles(scr));
7200 239 });
7201 239 }
7202 53376 void toggle_switches(dword flags, bool entry, const screen_handles_t& screen_handles)
7203 {
7204
2/2
✓ Branch 0 taken 737 times.
✓ Branch 1 taken 52639 times.
53376 if(!flags) return; //No flags to toggle
7205
7206 737 mapscr* m = screen_handles[0].base_scr;
7207 737 int screen = m->screen;
7208 737 bool is_active_screen = is_in_current_region(m);
7209
7210 305041 for_every_rpos_in_screen(screen_handles, [&](const rpos_handle_t& rpos_handle) {
7211 304304 byte togglegrid[176] = {0};
7212 304304 mapscr* scr = rpos_handle.scr;
7213 304304 int lyr = rpos_handle.layer;
7214 304304 int pos = rpos_handle.pos;
7215 304304 newcombo const& cmb = combobuf[scr->data[pos]];
7216
2/2
✓ Branch 0 taken 39424 times.
✓ Branch 1 taken 264880 times.
304304 if(is_active_screen)
7217
2/2
✓ Branch 0 taken 264880 times.
✓ Branch 1 taken 102893 times.
367773 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
7218 {
7219 102893 auto& trig = cmb.triggers[idx];
7220
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 102893 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
102893 if((trig.triggerflags[3] & combotriggerTRIGLEVELSTATE) && trig.trig_lstate < 32)
7221 if(flags&(1<<trig.trig_lstate))
7222 {
7223 auto oldcombo = rpos_handle.data();
7224 do_trigger_combo(rpos_handle, idx, ctrigSWITCHSTATE);
7225 if(rpos_handle.data() != oldcombo) break;
7226 }
7227 367773 }
7228
3/4
✓ Branch 0 taken 303641 times.
✓ Branch 1 taken 663 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2760 times.
304304 if((cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK) && cmb.attribytes[0] < 32
7229
2/2
✓ Branch 0 taken 2760 times.
✓ Branch 1 taken 301544 times.
304304 && !(cmb.usrflags & cflag11)) //global state
7230 {
7231
2/2
✓ Branch 0 taken 446 times.
✓ Branch 1 taken 2314 times.
2760 if(flags&(1<<cmb.attribytes[0]))
7232 {
7233 2314 set<int32_t> oldData;
7234 //Increment the combo/cset by the attributes
7235 2314 int32_t cmbofs = (cmb.attributes[0]/10000L);
7236 2314 int32_t csofs = (cmb.attributes[1]/10000L);
7237
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 oldData.insert(scr->data[pos]);
7238
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 scr->data[pos] = BOUND_COMBO(scr->data[pos] + cmbofs);
7239 2314 scr->cset[pos] = (scr->cset[pos] + csofs) & 15;
7240
4/4
✓ Branch 0 taken 1435 times.
✓ Branch 1 taken 879 times.
✓ Branch 2 taken 1197 times.
✓ Branch 3 taken 238 times.
2314 if(entry && (cmb.usrflags&cflag8))
7241 {
7242 238 newcombo const* tmp = &combobuf[scr->data[pos]];
7243
2/4
✓ Branch 0 taken 238 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 238 times.
✗ Branch 3 not taken.
238 while(tmp->can_cycle())
7244 {
7245 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7246 auto cid = cycle_under ? scr->undercombo : tmp->nextcombo;
7247 if(oldData.find(cid) != oldData.end())
7248 break;
7249
7250 scr->data[pos] = cid;
7251 if(!(tmp->animflags & AF_CYCLENOCSET))
7252 scr->cset[pos] = cycle_under ? scr->undercset : tmp->nextcset;
7253 oldData.insert(cid);
7254 tmp = &combobuf[cid];
7255 }
7256 238 }
7257 2314 int32_t cmbid = scr->data[pos];
7258
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 2273 times.
2314 if(combobuf[cmbid].animflags & AF_CYCLE)
7259 {
7260 41 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7261 41 combobuf[cmbid].cur_frame=0;
7262 41 combobuf[cmbid].aclk = 0;
7263
1/2
✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
41 combo_caches::drawing.refresh(cmbid);
7264 41 }
7265 2314 togglegrid[pos] |= (1<<lyr); //Mark this pos toggled for this layer
7266
2/2
✓ Branch 0 taken 511 times.
✓ Branch 1 taken 1803 times.
2314 if(cmb.type == cCSWITCH) return; //Switches don't toggle other layers
7267
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2147 times.
2147 for(int32_t lyr2 = 0; lyr2 < 7; ++lyr2) //Toggle same pos on other layers, if flag set
7268 {
7269
2/2
✓ Branch 0 taken 1671 times.
✓ Branch 1 taken 476 times.
2147 if(lyr==lyr2) return;
7270
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 344 times.
476 if(!(cmb.usrflags&(1<<lyr2))) return;
7271
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 if(togglegrid[pos]&(1<<lyr2)) return;
7272
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
344 mapscr* scr_2 = (lyr2 ? get_scr_layer(screen, lyr2) : m);
7273
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 if(!scr_2->data[pos]) //Don't increment empty space
7274 return;
7275 344 newcombo const& cmb_2 = combobuf[scr_2->data[pos]];
7276
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
344 if(lyr2 > lyr && (cmb_2.type == cCSWITCH || cmb_2.type == cCSWITCHBLOCK) && !(cmb.usrflags & cflag11)
7277 && cmb_2.attribytes[0] < 32 && (flags&(1<<cmb_2.attribytes[0])))
7278 return; //This is a switch/block that will be hit later in the loop!
7279 344 set<int32_t> oldData2;
7280 //Increment the combo/cset by the original cmb's attributes
7281
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 oldData2.insert(scr_2->data[pos]);
7282
1/2
✓ Branch 0 taken 344 times.
✗ Branch 1 not taken.
344 scr_2->data[pos] = BOUND_COMBO(scr_2->data[pos] + cmbofs);
7283 344 scr_2->cset[pos] = (scr_2->cset[pos] + csofs) & 15;
7284
3/4
✓ Branch 0 taken 50 times.
✓ Branch 1 taken 294 times.
✓ Branch 2 taken 50 times.
✗ Branch 3 not taken.
344 if(entry && (cmb.usrflags&cflag8)) //Skip cycling on screen entry
7285 {
7286 newcombo const* tmp = &combobuf[scr_2->data[pos]];
7287 while(tmp->can_cycle())
7288 {
7289 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7290 auto cid = cycle_under ? scr_2->undercombo : tmp->nextcombo;
7291 if(oldData2.find(cid) != oldData2.end())
7292 break;
7293
7294 scr_2->data[pos] = cid;
7295 if(!(tmp->animflags & AF_CYCLENOCSET))
7296 scr_2->cset[pos] = cycle_under ? scr_2->undercset : tmp->nextcset;
7297 oldData2.insert(cid);
7298 tmp = &combobuf[cid];
7299 }
7300 }
7301 344 int32_t cmbid2 = scr_2->data[pos];
7302
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 344 times.
344 if(combobuf[cmbid2].animflags & AF_CYCLE)
7303 {
7304 combobuf[cmbid2].tile = combobuf[cmbid2].o_tile;
7305 combobuf[cmbid2].cur_frame=0;
7306 combobuf[cmbid2].aclk = 0;
7307 combo_caches::drawing.refresh(cmbid2);
7308 }
7309 344 togglegrid[pos] |= (1<<lyr2); //Mark this pos toggled for this layer
7310 344 }
7311
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 2314 times.
✗ Branch 2 not taken.
2314 }
7312 446 }
7313 304304 });
7314
7315
3/4
✓ Branch 0 taken 519 times.
✓ Branch 1 taken 218 times.
✓ Branch 2 taken 519 times.
✗ Branch 3 not taken.
737 if(get_qr(qr_SWITCHES_AFFECT_MOVINGBLOCKS) && mblock2.clk)
7316 {
7317 newcombo const& cmb = combobuf[mblock2.bcombo];
7318 if(!(cmb.usrflags & cflag11) && (cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK) && cmb.attribytes[0] < 32)
7319 {
7320 if(flags&(1<<cmb.attribytes[0]))
7321 {
7322 //Increment the combo/cset by the attributes
7323 int32_t cmbofs = (cmb.attributes[0]/10000L);
7324 int32_t csofs = (cmb.attributes[1]/10000L);
7325 mblock2.bcombo = BOUND_COMBO(mblock2.bcombo + cmbofs);
7326 mblock2.cs = (mblock2.cs + csofs) & 15;
7327 int32_t cmbid = mblock2.bcombo;
7328 if(combobuf[cmbid].animflags & AF_CYCLE)
7329 {
7330 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7331 combobuf[cmbid].cur_frame=0;
7332 combobuf[cmbid].aclk = 0;
7333 combo_caches::drawing.refresh(cmbid);
7334 }
7335 }
7336 }
7337 }
7338
7339
2/2
✓ Branch 0 taken 224 times.
✓ Branch 1 taken 513 times.
737 if (is_active_screen)
7340 {
7341 513 int screen_index_offset = get_region_screen_offset(m->screen);
7342 513 word c = m->numFFC();
7343
2/2
✓ Branch 0 taken 334 times.
✓ Branch 1 taken 513 times.
847 for (int q = 0; q < c; ++q)
7344 {
7345 334 auto ffc_handle = *m->getFFCHandle(q, screen_index_offset);
7346 334 auto& cmb = ffc_handle.combo();
7347
2/2
✓ Branch 0 taken 334 times.
✓ Branch 1 taken 29 times.
363 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
7348 {
7349 29 auto& trig = cmb.triggers[idx];
7350
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 29 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
29 if((trig.triggerflags[3] & combotriggerTRIGLEVELSTATE) && trig.trig_lstate < 32)
7351 if(flags&(1<<trig.trig_lstate))
7352 {
7353 auto oldcombo = ffc_handle.data();
7354 do_trigger_combo(ffc_handle, idx, ctrigSWITCHSTATE);
7355 if(ffc_handle.data() != oldcombo) break;
7356 }
7357 29 }
7358 334 }
7359 513 }
7360 53376 }
7361
7362 void toggle_gswitches(int32_t state, bool entry)
7363 {
7364 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
7365 toggle_gswitches(state, entry, create_screen_handles(scr));
7366 });
7367 }
7368 void toggle_gswitches(int32_t state, bool entry, const screen_handles_t& screen_handles)
7369 {
7370 bool states[256] = {false};
7371 states[state] = true;
7372 toggle_gswitches(states, entry, screen_handles);
7373 }
7374 14934665 void toggle_gswitches(bool* states, bool entry, const screen_handles_t& screen_handles)
7375 {
7376
1/2
✓ Branch 0 taken 14934665 times.
✗ Branch 1 not taken.
14934665 if(!states) return;
7377
7378 14934665 auto& combo_cache = combo_caches::gswitch;
7379 14934665 mapscr* base_scr = screen_handles[0].base_scr;
7380 14934665 int screen = base_scr->screen;
7381 14934665 bool is_active_screen = is_in_current_region(base_scr);
7382 14934665 byte togglegrid[176] = {0};
7383
2/2
✓ Branch 0 taken 14934665 times.
✓ Branch 1 taken 104542655 times.
119477320 for(int32_t lyr = 0; lyr <= 6; ++lyr)
7384 {
7385 104542655 mapscr* scr = screen_handles[lyr].scr;
7386
2/2
✓ Branch 0 taken 72689297 times.
✓ Branch 1 taken 31853358 times.
104542655 if (!scr)
7387 72689297 continue;
7388
7389
2/2
✓ Branch 0 taken 5606191008 times.
✓ Branch 1 taken 31853358 times.
5638044366 for(int32_t pos = 0; pos < 176; ++pos)
7390 {
7391 5606191008 int cid = scr->data[pos];
7392 5606191008 auto& mini_cmb = combo_cache.minis[cid];
7393
7394
2/2
✓ Branch 0 taken 93474656 times.
✓ Branch 1 taken 5512716352 times.
5606191008 if (is_active_screen)
7395 {
7396
2/2
✓ Branch 0 taken 5512714470 times.
✓ Branch 1 taken 1882 times.
5512716352 if (mini_cmb.trigger_global_state)
7397 {
7398 1882 auto& cmb = combobuf[cid];
7399
2/2
✓ Branch 0 taken 1882 times.
✓ Branch 1 taken 1882 times.
3764 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
7400 {
7401 1882 auto& trig = cmb.triggers[idx];
7402
2/4
✓ Branch 0 taken 1882 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1882 times.
✗ Branch 3 not taken.
1882 if ((trig.triggerflags[3] & combotriggerTRIGGLOBALSTATE) && states[trig.trig_gstate])
7403 {
7404 auto rpos_handle = get_rpos_handle_for_screen(screen, lyr, pos);
7405 do_trigger_combo(rpos_handle, idx, ctrigSWITCHSTATE);
7406 if(rpos_handle.data() != cid) break;
7407 }
7408 1882 }
7409 1882 }
7410 5512716352 }
7411
7412
2/2
✓ Branch 0 taken 40395 times.
✓ Branch 1 taken 5606150613 times.
5606191008 if (!mini_cmb.has_global_state)
7413 5606150613 continue;
7414
7415 40395 newcombo const& cmb = combobuf[cid];
7416
2/4
✓ Branch 0 taken 40395 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 40395 times.
40395 if(cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK)
7417 {
7418 if(states[cmb.attribytes[0]])
7419 {
7420 set<int32_t> oldData;
7421 //Increment the combo/cset by the attributes
7422 int32_t cmbofs = (cmb.attributes[0]/10000L);
7423 int32_t csofs = (cmb.attributes[1]/10000L);
7424 oldData.insert(scr->data[pos]);
7425 scr->data[pos] = BOUND_COMBO(scr->data[pos] + cmbofs);
7426 scr->cset[pos] = (scr->cset[pos] + csofs) & 15;
7427 if(entry && (cmb.usrflags&cflag8))
7428 {
7429 newcombo const* tmp = &combobuf[scr->data[pos]];
7430 while(tmp->can_cycle())
7431 {
7432 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7433 auto cid = cycle_under ? scr->undercombo : tmp->nextcombo;
7434 if(oldData.find(cid) != oldData.end())
7435 break;
7436 scr->data[pos] = cid;
7437 if(!(tmp->animflags & AF_CYCLENOCSET))
7438 scr->cset[pos] = cycle_under ? scr->undercset : tmp->nextcset;
7439 oldData.insert(cid);
7440 tmp = &combobuf[cid];
7441 }
7442 }
7443 int32_t cmbid = scr->data[pos];
7444 if(combobuf[cmbid].animflags & AF_CYCLE)
7445 {
7446 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7447 combobuf[cmbid].cur_frame=0;
7448 combobuf[cmbid].aclk = 0;
7449 combo_caches::drawing.refresh(cmbid);
7450 }
7451 togglegrid[pos] |= (1<<lyr); //Mark this pos toggled for this layer
7452 if(cmb.type == cCSWITCH) continue; //Switches don't toggle other layers
7453 for(int32_t lyr2 = 0; lyr2 <= 6; ++lyr2) //Toggle same pos on other layers, if flag set
7454 {
7455 if(lyr==lyr2) continue;
7456 if(!(cmb.usrflags&(1<<lyr2))) continue;
7457 if(togglegrid[pos]&(1<<lyr2)) continue;
7458 mapscr* scr_2 = lyr2 == 0 ? base_scr : get_scr_layer_valid(screen, lyr2);
7459 if(!scr_2 || !scr_2->data[pos]) //Don't increment empty space
7460 continue;
7461 newcombo const& cmb_2 = combobuf[scr_2->data[pos]];
7462 if(lyr2 > lyr && (cmb_2.type == cCSWITCH || cmb_2.type == cCSWITCHBLOCK)
7463 && (cmb_2.usrflags & cflag11) && (states[cmb_2.attribytes[0]]))
7464 continue; //This is a switch/block that will be hit later in the loop!
7465 set<int32_t> oldData2;
7466 //Increment the combo/cset by the original cmb's attributes
7467 oldData2.insert(scr_2->data[pos]);
7468 scr_2->data[pos] = BOUND_COMBO(scr_2->data[pos] + cmbofs);
7469 scr_2->cset[pos] = (scr_2->cset[pos] + csofs) & 15;
7470 if(entry && (cmb.usrflags&cflag8)) //Skip cycling on screen entry
7471 {
7472 newcombo const* tmp = &combobuf[scr_2->data[pos]];
7473 while(tmp->can_cycle())
7474 {
7475 bool cycle_under = (tmp->animflags & AF_CYCLEUNDERCOMBO);
7476 auto cid = cycle_under ? scr_2->undercombo : tmp->nextcombo;
7477 if(oldData2.find(cid) != oldData2.end())
7478 break;
7479 scr_2->data[pos] = cid;
7480 if(!(tmp->animflags & AF_CYCLENOCSET))
7481 scr_2->cset[pos] = cycle_under ? scr_2->undercset : tmp->nextcset;
7482 oldData2.insert(cid);
7483 tmp = &combobuf[cid];
7484 }
7485 }
7486 int32_t cmbid2 = scr_2->data[pos];
7487 if(combobuf[cmbid2].animflags & AF_CYCLE)
7488 {
7489 combobuf[cmbid2].tile = combobuf[cmbid2].o_tile;
7490 combobuf[cmbid2].cur_frame=0;
7491 combobuf[cmbid2].aclk = 0;
7492 combo_caches::drawing.refresh(cmbid2);
7493 }
7494 togglegrid[pos] |= (1<<lyr2); //Mark this pos toggled for this layer
7495 }
7496 }
7497 }
7498 40395 }
7499 31853358 }
7500
7501
4/4
✓ Branch 0 taken 535390 times.
✓ Branch 1 taken 14399275 times.
✓ Branch 2 taken 4744 times.
✓ Branch 3 taken 530646 times.
14934665 if(get_qr(qr_SWITCHES_AFFECT_MOVINGBLOCKS) && mblock2.clk)
7502 {
7503 4744 newcombo const& cmb = combobuf[mblock2.bcombo];
7504
2/4
✓ Branch 0 taken 4744 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4744 times.
✗ Branch 3 not taken.
4744 if((cmb.type == cCSWITCH || cmb.type == cCSWITCHBLOCK) && (cmb.usrflags & cflag11))
7505 {
7506 if(states[cmb.attribytes[0]])
7507 {
7508 //Increment the combo/cset by the attributes
7509 int32_t cmbofs = (cmb.attributes[0]/10000L);
7510 int32_t csofs = (cmb.attributes[1]/10000L);
7511 mblock2.bcombo = BOUND_COMBO(mblock2.bcombo + cmbofs);
7512 mblock2.cs = (mblock2.cs + csofs) & 15;
7513 int32_t cmbid = mblock2.bcombo;
7514 if(combobuf[cmbid].animflags & AF_CYCLE)
7515 {
7516 combobuf[cmbid].tile = combobuf[cmbid].o_tile;
7517 combobuf[cmbid].cur_frame=0;
7518 combobuf[cmbid].aclk = 0;
7519 combo_caches::drawing.refresh(cmbid);
7520 }
7521 }
7522 }
7523 4744 }
7524
7525
2/2
✓ Branch 0 taken 413475 times.
✓ Branch 1 taken 14521190 times.
14934665 if(is_active_screen)
7526 {
7527 14521190 int screen_index_offset = get_region_screen_offset(screen);
7528 14521190 word c = base_scr->numFFC();
7529
2/2
✓ Branch 0 taken 433152690 times.
✓ Branch 1 taken 14521190 times.
447673880 for (int q = 0; q < c; ++q)
7530 {
7531 433152690 auto ffc_handle = *base_scr->getFFCHandle(q, screen_index_offset);
7532 433152690 int cid = ffc_handle.data();
7533 // auto& mini_cmb = combo_cache.minis[cid];
7534 // if (mini_cmb.trigger_global_state)
7535 433152690 auto& cmb = combobuf[cid];
7536
2/2
✓ Branch 0 taken 433152690 times.
✓ Branch 1 taken 228788 times.
433381478 for(size_t idx = 0; idx < cmb.triggers.size(); ++idx)
7537 {
7538 228788 auto& trig = cmb.triggers[idx];
7539
1/2
✓ Branch 0 taken 228788 times.
✗ Branch 1 not taken.
228788 if (states[trig.trig_gstate])
7540 do_trigger_combo(ffc_handle, idx, ctrigSWITCHSTATE);
7541
1/2
✓ Branch 0 taken 228788 times.
✗ Branch 1 not taken.
228788 if(ffc_handle.data() != cid) break;
7542 228788 }
7543 433152690 }
7544 14521190 }
7545 14934665 }
7546 53137 void toggle_gswitches_load(const screen_handles_t& screen_handles)
7547 {
7548 bool states[256];
7549
2/2
✓ Branch 0 taken 13603072 times.
✓ Branch 1 taken 53137 times.
13656209 for(auto q = 0; q < 256; ++q)
7550 {
7551 13603072 states[q] = game->gswitch_timers[q] != 0;
7552 13603072 }
7553 53137 toggle_gswitches(states, true, screen_handles);
7554 53137 }
7555 14492160 void run_gswitch_timers()
7556 {
7557 14492160 bool states[256] = {false};
7558 14492160 auto& m = game->gswitch_timers.mut_inner();
7559
2/2
✓ Branch 0 taken 3705950720 times.
✓ Branch 1 taken 14492160 times.
3720442880 for(auto it = m.begin(); it != m.end();)
7560 {
7561
1/2
✓ Branch 0 taken 3705950720 times.
✗ Branch 1 not taken.
3705950720 if(it->second > 0)
7562 if(!--it->second)
7563 {
7564 states[it->first] = true;
7565 it = m.erase(it);
7566 continue;
7567 }
7568 3705950720 ++it;
7569 }
7570 29373688 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
7571 14881528 toggle_gswitches(states, false, create_screen_handles(scr));
7572 14881528 });
7573 14492160 }
7574 1077 void onload_gswitch_timers() //Reset all timers that were counting down, no trigger necessary
7575 {
7576
2/2
✓ Branch 0 taken 275712 times.
✓ Branch 1 taken 1077 times.
276789 for(auto q = 0; q < 256; ++q)
7577 {
7578
1/2
✓ Branch 0 taken 275712 times.
✗ Branch 1 not taken.
275712 if(game->gswitch_timers[q] > 0)
7579 game->gswitch_timers[q] = 0;
7580 275712 }
7581 1077 }
7582
7583 /**** View Map ****/
7584
7585 int32_t mapres = 0;
7586 int32_t view_map_show_mode = 3;
7587
7588 124544 bool displayOnMap(int32_t x, int32_t y)
7589 {
7590 124544 int32_t s = (y<<4) + x;
7591 124544 int mi = mapind(cur_map, s);
7592
2/2
✓ Branch 0 taken 67891 times.
✓ Branch 1 taken 56653 times.
124544 if (!(game->maps[mi]&mVISITED))
7593 67891 return false;
7594
7595 // Don't display if not part of DMap
7596
4/4
✓ Branch 0 taken 15628 times.
✓ Branch 1 taken 41025 times.
✓ Branch 2 taken 4655 times.
✓ Branch 3 taken 4311 times.
65619 if(((DMaps[cur_dmap].flags&dmfDMAPMAP) &&
7597
1/2
✓ Branch 0 taken 15628 times.
✗ Branch 1 not taken.
15628 (DMaps[cur_dmap].type != dmOVERW) &&
7598
2/2
✓ Branch 0 taken 12495 times.
✓ Branch 1 taken 3133 times.
15628 !(x >= DMaps[cur_dmap].xoff &&
7599
2/2
✓ Branch 0 taken 8966 times.
✓ Branch 1 taken 3529 times.
12495 x < DMaps[cur_dmap].xoff+8 &&
7600 8966 DMaps[cur_dmap].grid[y]&(128>>(x-DMaps[cur_dmap].xoff)))))
7601 10973 return false;
7602 else
7603 45680 return true;
7604 124544 }
7605
7606 973 void ViewMap()
7607 {
7608 973 ViewingMap = true;
7609
7610 973 BITMAP* mappic = NULL;
7611 static double scales[17] =
7612 {
7613 0.03125, 0.04419, 0.0625, 0.08839, 0.125, 0.177, 0.25, 0.3535,
7614 0.50, 0.707, 1.0, 1.414, 2.0, 2.828, 4.0, 5.657, 8.0
7615 };
7616
7617 973 int32_t px = ((8-(cur_screen&15)) << 9) - 256;
7618 973 int32_t py = ((4-(cur_screen>>4)) * 352) - 176;
7619 973 int32_t lx = ((cur_screen&15)<<8) + HeroX()+8;
7620 973 int32_t ly = ((cur_screen>>4)*176) + HeroY()+8;
7621 973 int32_t sc = 6;
7622
7623 973 bool done=false, redraw=true;
7624
7625 973 mappic = create_bitmap_ex(8,(256*16)>>mapres,(176*8)>>mapres);
7626
7627
1/2
✓ Branch 0 taken 973 times.
✗ Branch 1 not taken.
973 if(!mappic)
7628 {
7629 enter_sys_pal();
7630 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
7631 exit_sys_pal();
7632 return;
7633 }
7634
7635 973 clear_to_color(mappic, WHITE);
7636
7637 973 auto prev_viewport = viewport;
7638 973 viewport.x = 0;
7639 973 viewport.y = 0;
7640
7641 // draw the map
7642 973 BITMAP* screen_bmp = create_bitmap_ex(8, 256, 176);
7643 973 combotile_add_x = 256;
7644 973 combotile_add_y = 0;
7645
2/2
✓ Branch 0 taken 7784 times.
✓ Branch 1 taken 973 times.
8757 for(int32_t y=0; y<8; y++)
7646 {
7647
2/2
✓ Branch 0 taken 124544 times.
✓ Branch 1 taken 7784 times.
132328 for(int32_t x=0; x<16; x++)
7648 {
7649
2/2
✓ Branch 0 taken 45680 times.
✓ Branch 1 taken 78864 times.
124544 if (!displayOnMap(x, y))
7650 78864 continue;
7651
7652 45680 int screen = map_scr_xy_to_index(x, y);
7653 45680 auto scrs = loadscr2(screen);
7654 45680 mapscr* scr = &scrs[0];
7655
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 if (!scr->is_valid())
7656 continue;
7657
7658 screen_handles_t screen_handles;
7659
2/2
✓ Branch 0 taken 45680 times.
✓ Branch 1 taken 319760 times.
365440 for (int i = 0; i <= 6; i++)
7660
3/4
✓ Branch 0 taken 319760 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 103790 times.
✓ Branch 3 taken 215970 times.
319760 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
7661
7662 45680 int xx = 0;
7663 45680 int yy = -playing_field_offset;
7664
7665
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 45660 times.
45680 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
7666 {
7667
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 do_layer(screen_bmp, 0, screen_handles[2], xx, yy);
7668
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 do_ffc_layer(screen_bmp, -2, screen_handles[0], xx, yy);
7669 20 }
7670
7671
2/2
✓ Branch 0 taken 175 times.
✓ Branch 1 taken 45505 times.
45680 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
7672 {
7673
1/2
✓ Branch 0 taken 175 times.
✗ Branch 1 not taken.
175 do_layer(screen_bmp, 0, screen_handles[3], xx, yy);
7674
1/2
✓ Branch 0 taken 175 times.
✗ Branch 1 not taken.
175 do_ffc_layer(screen_bmp, -3, screen_handles[0], xx, yy);
7675 175 }
7676
7677
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
✗ Branch 3 not taken.
45680 if(lenscheck(scr,0)) putscr(scr, screen_bmp, 0, 0);
7678
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 0, screen_handles[0], xx, yy);
7679
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[1], xx, yy);
7680
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 1, screen_handles[0], xx, yy);
7681
7682
2/2
✓ Branch 0 taken 45660 times.
✓ Branch 1 taken 20 times.
45680 if(!XOR((scr->flags7&fLAYER2BG), DMaps[cur_dmap].flags&dmfLAYER2BG))
7683 {
7684
1/2
✓ Branch 0 taken 45660 times.
✗ Branch 1 not taken.
45660 do_layer(screen_bmp, 0, screen_handles[2], xx, yy);
7685
1/2
✓ Branch 0 taken 45660 times.
✗ Branch 1 not taken.
45660 do_ffc_layer(screen_bmp, 2, screen_handles[0], xx, yy);
7686 45660 }
7687
7688
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 putscrdoors(scr, screen_bmp, xx, yy);
7689
2/2
✓ Branch 0 taken 41678 times.
✓ Branch 1 taken 4002 times.
45680 if (get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
7690 {
7691
1/2
✓ Branch 0 taken 41678 times.
✗ Branch 1 not taken.
41678 do_layer(screen_bmp, -2, screen_handles[0], xx, yy);
7692
2/2
✓ Branch 0 taken 1782 times.
✓ Branch 1 taken 39896 times.
41678 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
7693 {
7694
1/2
✓ Branch 0 taken 1782 times.
✗ Branch 1 not taken.
1782 do_layer(screen_bmp,-2, screen_handles[1], xx, yy);
7695
1/2
✓ Branch 0 taken 1782 times.
✗ Branch 1 not taken.
1782 do_layer(screen_bmp,-2, screen_handles[2], xx, yy);
7696 1782 }
7697 41678 }
7698
7699
2/2
✓ Branch 0 taken 45505 times.
✓ Branch 1 taken 175 times.
45680 if(!XOR((scr->flags7&fLAYER3BG), DMaps[cur_dmap].flags&dmfLAYER3BG))
7700 {
7701
1/2
✓ Branch 0 taken 45505 times.
✗ Branch 1 not taken.
45505 do_layer(screen_bmp, 0, screen_handles[3], xx, yy);
7702
1/2
✓ Branch 0 taken 45505 times.
✗ Branch 1 not taken.
45505 do_ffc_layer(screen_bmp, 3, screen_handles[0], xx, yy);
7703 45505 }
7704
7705
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[4], xx, yy);
7706
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 4, screen_handles[0], xx, yy);
7707
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, -1, screen_handles[0], xx, yy);
7708
2/2
✓ Branch 0 taken 5784 times.
✓ Branch 1 taken 39896 times.
45680 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
7709 {
7710
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 do_layer(screen_bmp,-1, screen_handles[1], xx, yy);
7711
1/2
✓ Branch 0 taken 5784 times.
✗ Branch 1 not taken.
5784 do_layer(screen_bmp,-1, screen_handles[2], xx, yy);
7712 5784 }
7713
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[5], xx, yy);
7714
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 5, screen_handles[0], xx, yy);
7715
2/4
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45680 times.
45680 if(replay_version_check(40))
7716 do_ffc_layer(screen_bmp, -1, screen_handles[0], xx, yy);
7717
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_layer(screen_bmp, 0, screen_handles[6], xx, yy);
7718
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 6, screen_handles[0], xx, yy);
7719
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 do_ffc_layer(screen_bmp, 7, screen_handles[0], xx, yy);
7720
7721
1/2
✓ Branch 0 taken 45680 times.
✗ Branch 1 not taken.
45680 stretch_blit(screen_bmp, mappic, 0, 0, 256, 176, x<<(8-mapres), (y*176)>>mapres, 256>>mapres, 176>>mapres);
7722
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 45680 times.
45680 }
7723 7784 }
7724
7725 973 viewport = prev_viewport;
7726 973 combotile_add_x = 0;
7727 973 combotile_add_y = 0;
7728
7729 973 destroy_bitmap(screen_bmp);
7730 973 clear_keybuf();
7731 973 pause_all_sfx();
7732
7733 // view it
7734 973 int32_t delay = 0;
7735
7736 973 do
7737 {
7738
2/2
✓ Branch 0 taken 178717 times.
✓ Branch 1 taken 29891 times.
208608 if (replay_version_check(0, 11))
7739 29891 load_control_state();
7740
7741 208608 int32_t step = int32_t(16.0/scales[sc]);
7742 208608 step = (step>>1) + (step&1);
7743 208608 bool r = cRbtn();
7744
7745
1/2
✓ Branch 0 taken 208608 times.
✗ Branch 1 not taken.
208608 if(cLbtn())
7746 {
7747 step <<= 2;
7748 delay = 0;
7749 }
7750
7751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 208608 times.
208608 if(r)
7752 {
7753 if(rUp())
7754 {
7755 py+=step;
7756 redraw=true;
7757 }
7758
7759 if(rDown())
7760 {
7761 py-=step;
7762 redraw=true;
7763 }
7764
7765 if(rLeft())
7766 {
7767 px+=step;
7768 redraw=true;
7769 }
7770
7771 if(rRight())
7772 {
7773 px-=step;
7774 redraw=true;
7775 }
7776 }
7777 else
7778 {
7779
2/2
✓ Branch 0 taken 193729 times.
✓ Branch 1 taken 14879 times.
208608 if(Up())
7780 {
7781 14879 py+=step;
7782 14879 redraw=true;
7783 14879 }
7784
7785
2/2
✓ Branch 0 taken 193574 times.
✓ Branch 1 taken 15034 times.
208608 if(Down())
7786 {
7787 15034 py-=step;
7788 15034 redraw=true;
7789 15034 }
7790
7791
2/2
✓ Branch 0 taken 182159 times.
✓ Branch 1 taken 26449 times.
208608 if(Left())
7792 {
7793 26449 px+=step;
7794 26449 redraw=true;
7795 26449 }
7796
7797
2/2
✓ Branch 0 taken 182774 times.
✓ Branch 1 taken 25834 times.
208608 if(Right())
7798 {
7799 25834 px-=step;
7800 25834 redraw=true;
7801 25834 }
7802 }
7803
7804
2/2
✓ Branch 0 taken 187444 times.
✓ Branch 1 taken 21164 times.
208608 if(delay)
7805 21164 --delay;
7806 else
7807 {
7808 187444 bool a = cAbtn();
7809 187444 bool b = cBbtn();
7810
7811
3/4
✓ Branch 0 taken 1721 times.
✓ Branch 1 taken 185723 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1721 times.
187444 if(a && !b)
7812 {
7813
1/2
✓ Branch 0 taken 1721 times.
✗ Branch 1 not taken.
1721 sc=zc_min(sc+1,16);
7814 1721 delay=8;
7815 1721 redraw=true;
7816 1721 }
7817
7818
3/4
✓ Branch 0 taken 927 times.
✓ Branch 1 taken 186517 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 927 times.
187444 if(b && !a)
7819 {
7820
2/2
✓ Branch 0 taken 926 times.
✓ Branch 1 taken 1 times.
927 sc=zc_max(sc-1,0);
7821 927 delay=8;
7822 927 redraw=true;
7823 927 }
7824 }
7825
7826
2/2
✓ Branch 0 taken 208597 times.
✓ Branch 1 taken 11 times.
208608 if(rPbtn())
7827 11 --view_map_show_mode;
7828
7829 208608 px = vbound(px,-4096,4096);
7830 208608 py = vbound(py,-1408,1408);
7831
7832 208608 double scale = scales[sc];
7833
7834
2/2
✓ Branch 0 taken 72838 times.
✓ Branch 1 taken 135770 times.
208608 if(!redraw)
7835 {
7836 135770 blit(scrollbuf_old,framebuf,256,0,0,0,256,232);
7837 135770 }
7838 else
7839 {
7840 72838 clear_to_color(framebuf,BLACK);
7841 145676 stretch_blit(mappic,framebuf,0,0,mappic->w,mappic->h,
7842 72838 int32_t(256+(int64_t(px)-mappic->w)*scale)/2,int32_t(224+(int64_t(py)-mappic->h)*scale)/2,
7843 72838 int32_t(mappic->w*scale),int32_t(mappic->h*scale));
7844
7845 72838 blit(framebuf,scrollbuf_old,0,0,256,0,256,232);
7846 72838 redraw=false;
7847 }
7848
7849 208608 int32_t x = int32_t(256+(px-((2048-int64_t(lx))*2))*scale)/2;
7850 208608 int32_t y = int32_t(224+(py-((704-int64_t(ly))*2))*scale)/2;
7851
7852
2/2
✓ Branch 0 taken 7466 times.
✓ Branch 1 taken 201142 times.
208608 if(view_map_show_mode&1)
7853 {
7854 201142 line(framebuf,x-7,y-7,x+7,y+7,(frame&3)+252);
7855 201142 line(framebuf,x+7,y-7,x-7,y+7,(frame&3)+252);
7856 201142 }
7857
7858
3/4
✓ Branch 0 taken 5600 times.
✓ Branch 1 taken 203008 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5600 times.
208608 if(view_map_show_mode&2 || r)
7859 203008 textprintf_ex(framebuf,font,224,216,WHITE,BLACK,"%1.2f",scale);
7860
7861
1/2
✓ Branch 0 taken 208608 times.
✗ Branch 1 not taken.
208608 if(r)
7862 {
7863 textprintf_ex(framebuf,font,0,208,WHITE,BLACK,"m: %d %d",px,py);
7864 textprintf_ex(framebuf,font,0,216,WHITE,BLACK,"x: %d %d",x,y);
7865 }
7866
7867 208608 advanceframe(false, false);
7868
2/2
✓ Branch 0 taken 29891 times.
✓ Branch 1 taken 178717 times.
208608 if (replay_version_check(11))
7869 178717 load_control_state();
7870
7871
2/2
✓ Branch 0 taken 207636 times.
✓ Branch 1 taken 972 times.
208608 if(getInput(btnS, true, false, true)) //rSbtn
7872 972 done = true;
7873
7874
2/2
✓ Branch 0 taken 973 times.
✓ Branch 1 taken 207635 times.
417216 }
7875
2/2
✓ Branch 0 taken 972 times.
✓ Branch 1 taken 207636 times.
208608 while(!done && !Quit);
7876
7877 973 ViewingMap = false;
7878 973 destroy_bitmap(mappic);
7879 973 resume_all_sfx();
7880 973 }
7881
7882 1075 int32_t onViewMap()
7883 {
7884
4/6
✓ Branch 0 taken 1075 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1075 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 102 times.
✓ Branch 5 taken 973 times.
1075 if(Playing && cur_screen<128 && DMaps[cur_dmap].flags&dmfVIEWMAP)
7885 {
7886 973 clear_to_color(framebuf,BLACK);
7887 973 textout_centre_ex(framebuf,font,"Drawing map...",128,108,WHITE,BLACK);
7888 973 advanceframe(true);
7889 973 ViewMap();
7890 973 }
7891
7892 1075 return D_O_K;
7893 }
7894
7895 35154871 bool isGrassType(int32_t type)
7896 {
7897
2/2
✓ Branch 0 taken 34485061 times.
✓ Branch 1 taken 669810 times.
35154871 switch(type)
7898 {
7899 case cTALLGRASS:
7900 case cTALLGRASSNEXT:
7901 case cTALLGRASSTOUCHY:
7902 669810 return true;
7903 }
7904
7905 34485061 return false;
7906 35154871 }
7907
7908 20489 bool isFlowersType(int32_t type)
7909 {
7910
2/2
✓ Branch 0 taken 16149 times.
✓ Branch 1 taken 4340 times.
20489 switch(type)
7911 {
7912 case cFLOWERS:
7913 case cFLOWERSTOUCHY:
7914 4340 return true;
7915 }
7916
7917 16149 return false;
7918 20489 }
7919
7920 bool isGenericType(int32_t type)
7921 {
7922 switch(type)
7923 {
7924 case cTRIGGERGENERIC:
7925 return true;
7926 }
7927
7928 return false;
7929 }
7930
7931 25628 bool isBushType(int32_t type)
7932 {
7933
2/2
✓ Branch 0 taken 20489 times.
✓ Branch 1 taken 5139 times.
25628 switch(type)
7934 {
7935 case cBUSH:
7936 case cBUSHNEXT:
7937 case cBUSHTOUCHY:
7938 case cBUSHNEXTTOUCHY:
7939
7940 5139 return true;
7941 }
7942
7943 20489 return false;
7944 25628 }
7945
7946 bool isSlashType(int32_t type)
7947 {
7948 switch(type)
7949 {
7950 case cSLASH:
7951 case cSLASHITEM:
7952 case cSLASHTOUCHY:
7953 case cSLASHITEMTOUCHY:
7954 case cSLASHNEXT:
7955 case cSLASHNEXTITEM:
7956 case cSLASHNEXTTOUCHY:
7957 case cSLASHNEXTITEMTOUCHY:
7958 return true;
7959 }
7960
7961 return false;
7962 }
7963
7964 15292 bool isCuttableNextType(int32_t type)
7965 {
7966
2/2
✓ Branch 0 taken 9385 times.
✓ Branch 1 taken 5907 times.
15292 switch(type)
7967 {
7968 case cSLASHNEXT:
7969 case cSLASHNEXTITEM:
7970 case cTALLGRASSNEXT:
7971 case cBUSHNEXT:
7972 case cSLASHNEXTTOUCHY:
7973 case cSLASHNEXTITEMTOUCHY:
7974 case cBUSHNEXTTOUCHY:
7975 5907 return true;
7976 }
7977
7978 9385 return false;
7979 15292 }
7980
7981 17118 bool isTouchyType(int32_t type)
7982 {
7983
2/2
✓ Branch 0 taken 6050 times.
✓ Branch 1 taken 11068 times.
17118 switch(type)
7984 {
7985 case cSLASHTOUCHY:
7986 case cSLASHITEMTOUCHY:
7987 case cBUSHTOUCHY:
7988 case cFLOWERSTOUCHY:
7989 case cTALLGRASSTOUCHY:
7990 case cSLASHNEXTTOUCHY:
7991 case cSLASHNEXTITEMTOUCHY:
7992 case cBUSHNEXTTOUCHY:
7993 11068 return true;
7994 }
7995
7996 6050 return false;
7997 17118 }
7998
7999 28781158 bool isCuttableType(int32_t type)
8000 {
8001
2/2
✓ Branch 0 taken 28340196 times.
✓ Branch 1 taken 440962 times.
28781158 switch(type)
8002 {
8003 case cSLASH:
8004 case cSLASHITEM:
8005 case cBUSH:
8006 case cFLOWERS:
8007 case cTALLGRASS:
8008 case cTALLGRASSNEXT:
8009 case cSLASHNEXT:
8010 case cSLASHNEXTITEM:
8011 case cBUSHNEXT:
8012
8013 case cSLASHTOUCHY:
8014 case cSLASHITEMTOUCHY:
8015 case cBUSHTOUCHY:
8016 case cFLOWERSTOUCHY:
8017 case cTALLGRASSTOUCHY:
8018 case cSLASHNEXTTOUCHY:
8019 case cSLASHNEXTITEMTOUCHY:
8020 case cBUSHNEXTTOUCHY:
8021 440962 return true;
8022 }
8023
8024 28340196 return false;
8025 28781158 }
8026
8027 16908 bool isCuttableItemType(int32_t type)
8028 {
8029
2/2
✓ Branch 0 taken 419 times.
✓ Branch 1 taken 16489 times.
16908 switch(type)
8030 {
8031 case cSLASHITEM:
8032 case cBUSH:
8033 case cFLOWERS:
8034 case cTALLGRASS:
8035 case cTALLGRASSNEXT:
8036 case cSLASHNEXTITEM:
8037 case cBUSHNEXT:
8038
8039 case cSLASHITEMTOUCHY:
8040 case cBUSHTOUCHY:
8041 case cFLOWERSTOUCHY:
8042 case cTALLGRASSTOUCHY:
8043 case cSLASHNEXTITEMTOUCHY:
8044 case cBUSHNEXTTOUCHY:
8045 16489 return true;
8046 }
8047
8048 419 return false;
8049 16908 }
8050
8051 66 bool is_push(mapscr* m, int32_t pos)
8052 {
8053
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if(is_push_flag(m->sflag[pos]))
8054 return true;
8055 66 newcombo const& cmb = combobuf[m->data[pos]];
8056
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if(is_push_flag(cmb.flag))
8057 return true;
8058
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 52 times.
66 if(cmb.type == cPUSHBLOCK)
8059 14 return true;
8060
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
52 if(cmb.type == cSWITCHHOOK && (cmb.usrflags&cflag7))
8061 return true; //Counts as 'pushblock' flag
8062 52 return false;
8063 66 }
8064
8065 407 static std::map<int, screen_state_t> screen_states;
8066
8067 35190 std::map<int, screen_state_t>& get_screen_states()
8068 {
8069 35190 return screen_states;
8070 }
8071
8072 43338238 screen_state_t& get_screen_state(int screen)
8073 {
8074 43338238 return screen_states[screen];
8075 }
8076
8077 536 void clear_screen_states()
8078 {
8079 536 screen_states.clear();
8080 536 }
8081
8082 1374 void screen_item_set_state(int screen, ScreenItemState state)
8083 {
8084 1374 get_screen_state(screen).item_state = state;
8085 1374 }
8086
8087 36346 void mark_visited(int screen)
8088 {
8089
2/2
✓ Branch 0 taken 475 times.
✓ Branch 1 taken 35871 times.
36346 if (screen < 0x80)
8090 {
8091
2/2
✓ Branch 0 taken 23951 times.
✓ Branch 1 taken 11920 times.
35871 if(DMaps[cur_dmap].flags&dmfVIEWMAP)
8092 11920 game->maps[mapind(cur_map, screen)] |= mVISITED;
8093
8094 35871 markBmap(-1, screen);
8095 35871 }
8096 36346 }
8097